From 84daf2559f37908e40c56a64f81c345e63ef8edc Mon Sep 17 00:00:00 2001 From: Alexander Emelin Date: Thu, 24 Sep 2020 11:25:33 +0300 Subject: [PATCH] fix ws close with custom disconnect (#155) --- changelog.md | 5 +++++ client.go | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index a37ff8a6..65e57be8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,8 @@ +v0.11.2 +======= + +* Fix non-working websocket close with custom disconnect code: this is a regression introduced by v0.11.0. + v0.11.1 ======= diff --git a/client.go b/client.go index 03b8f177..ba28a52b 100644 --- a/client.go +++ b/client.go @@ -601,7 +601,7 @@ func (c *Client) Handle(data []byte) bool { if len(data) == 0 { c.node.logger.log(newLogEntry(LogLevelError, "empty client request received", map[string]interface{}{"client": c.ID(), "user": c.UserID()})) - _ = c.close(DisconnectBadRequest) + go func() { _ = c.close(DisconnectBadRequest) }() return false } @@ -617,7 +617,7 @@ func (c *Client) Handle(data []byte) bool { break } c.node.logger.log(newLogEntry(LogLevelInfo, "error decoding command", map[string]interface{}{"data": string(data), "client": c.ID(), "user": c.UserID(), "error": err.Error()})) - _ = c.close(DisconnectBadRequest) + go func() { _ = c.close(DisconnectBadRequest) }() protocol.PutCommandDecoder(protoType, decoder) protocol.PutReplyEncoder(protoType, encoder) return false @@ -640,7 +640,7 @@ func (c *Client) Handle(data []byte) bool { } protocol.PutCommandDecoder(protoType, decoder) protocol.PutReplyEncoder(protoType, encoder) - _ = c.close(disconnect) + go func() { _ = c.close(disconnect) }() return fmt.Errorf("flush error") } } @@ -661,7 +661,7 @@ func (c *Client) Handle(data []byte) bool { if disconnect != DisconnectNormal { c.node.logger.log(newLogEntry(LogLevelInfo, "disconnect after handling command", map[string]interface{}{"command": fmt.Sprintf("%v", cmd), "client": c.ID(), "user": c.UserID(), "reason": disconnect.Reason})) } - _ = c.close(disconnect) + go func() { _ = c.close(disconnect) }() if encodeErr == nil { protocol.PutCommandDecoder(protoType, decoder) protocol.PutReplyEncoder(protoType, encoder) @@ -669,7 +669,7 @@ func (c *Client) Handle(data []byte) bool { return false } if encodeErr != nil { - _ = c.close(DisconnectServerError) + go func() { _ = c.close(DisconnectServerError) }() return false } } @@ -681,7 +681,7 @@ func (c *Client) Handle(data []byte) bool { if c.node.logger.enabled(LogLevelDebug) { c.node.logger.log(newLogEntry(LogLevelDebug, "disconnect after sending reply", map[string]interface{}{"client": c.ID(), "user": c.UserID(), "reason": disconnect.Reason})) } - _ = c.close(disconnect) + go func() { _ = c.close(disconnect) }() protocol.PutCommandDecoder(protoType, decoder) protocol.PutReplyEncoder(protoType, encoder) return false