Commit e8c732c5 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Fix error handling at websocket close.

parent 26e6ecc3
...@@ -657,13 +657,13 @@ func readMessage(conn *websocket.Conn, m *clientMessage) error { ...@@ -657,13 +657,13 @@ func readMessage(conn *websocket.Conn, m *clientMessage) error {
return conn.ReadJSON(&m) return conn.ReadJSON(&m)
} }
func StartClient(conn *websocket.Conn) error { func StartClient(conn *websocket.Conn) (err error) {
var m clientMessage var m clientMessage
err := readMessage(conn, &m) err = readMessage(conn, &m)
if err != nil { if err != nil {
conn.Close() conn.Close()
return err return
} }
if m.Type != "handshake" { if m.Type != "handshake" {
...@@ -674,7 +674,8 @@ func StartClient(conn *websocket.Conn) error { ...@@ -674,7 +674,8 @@ func StartClient(conn *websocket.Conn) error {
), ),
) )
conn.Close() conn.Close()
return group.ProtocolError("client didn't handshake") err = group.ProtocolError("client didn't handshake")
return
} }
c := &webClient{ c := &webClient{
...@@ -689,13 +690,14 @@ func StartClient(conn *websocket.Conn) error { ...@@ -689,13 +690,14 @@ func StartClient(conn *websocket.Conn) error {
c.writerDone = make(chan struct{}) c.writerDone = make(chan struct{})
go clientWriter(conn, c.writeCh, c.writerDone) go clientWriter(conn, c.writeCh, c.writerDone)
defer func() { defer func() {
var e []byte m, e := errorToWSCloseMessage(c.id, err)
if !isWSNormalError(err) { if isWSNormalError(err) {
var m *clientMessage err = nil
m, e = errorToWSCloseMessage(c.id, err) } else if _, ok := err.(group.KickError); ok {
if m != nil { err = nil
c.write(*m) }
} if m != nil {
c.write(*m)
} }
c.close(e) c.close(e)
}() }()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment