Skip to content

Commit

Permalink
fix ws close with custom disconnect (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia authored Sep 24, 2020
1 parent e8ee7f3 commit 84daf25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
=======

Expand Down
12 changes: 6 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand All @@ -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")
}
}
Expand All @@ -661,15 +661,15 @@ 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)
}
return false
}
if encodeErr != nil {
_ = c.close(DisconnectServerError)
go func() { _ = c.close(DisconnectServerError) }()
return false
}
}
Expand All @@ -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
Expand Down

0 comments on commit 84daf25

Please sign in to comment.