Skip to content

Commit

Permalink
fix possible goroutine leak on conn close, fix empty dev version in m…
Browse files Browse the repository at this point in the history
…etrics
  • Loading branch information
FZambia committed Nov 15, 2018
1 parent 94d0878 commit a70909c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion handler_sockjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (t *sockjsTransport) write(data ...[]byte) error {
// TODO: can actually be sent in single message as streaming JSON.
err := t.session.Send(string(payload))
if err != nil {
t.Close(DisconnectWriteError)
go t.Close(DisconnectWriteError)
return err
}
transportMessagesSent.WithLabelValues(transportSockJS).Inc()
Expand Down
6 changes: 3 additions & 3 deletions handler_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,21 @@ func (t *websocketTransport) write(data ...[]byte) error {
}
writer, err := t.conn.NextWriter(messageType)
if err != nil {
t.Close(DisconnectWriteError)
go t.Close(DisconnectWriteError)
return err
}
bytesOut := 0
for _, payload := range data {
n, err := writer.Write(payload)
if n != len(payload) || err != nil {
t.Close(DisconnectWriteError)
go t.Close(DisconnectWriteError)
return err
}
bytesOut += len(data)
}
err = writer.Close()
if err != nil {
t.Close(DisconnectWriteError)
go t.Close(DisconnectWriteError)
return err
}
if t.opts.writeTimeout > 0 {
Expand Down
6 changes: 5 additions & 1 deletion node.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ func (n *Node) updateGauges() {
numClientsGauge.Set(float64(n.hub.NumClients()))
numUsersGauge.Set(float64(n.hub.NumUsers()))
numChannelsGauge.Set(float64(n.hub.NumChannels()))
buildInfoGauge.WithLabelValues(n.Config().Version).Set(1)
version := n.Config().Version
if version == "" {
version = "_"
}
buildInfoGauge.WithLabelValues(version).Set(1)
}

func (n *Node) updateMetrics() {
Expand Down

0 comments on commit a70909c

Please sign in to comment.