Websocket: fixed memory leak on startPinger

Former-commit-id: fe6162dd8914398e1333850950e1898e89e75005
This commit is contained in:
Gerson Alexander Pardo Gamez 2017-10-16 17:54:17 -05:00 committed by GitHub
parent 1816b22870
commit dcde9d05a2

View File

@ -250,7 +250,7 @@ func newConnection(ctx context.Context, s *Server, underlineConn UnderlineConnec
// write writes a raw websocket message with a specific type to the client
// used by ping messages and any CloseMessage types.
func (c *connection) write(websocketMessageType int, data []byte) {
func (c *connection) write(websocketMessageType int, data []byte) error {
// for any-case the app tries to write from different goroutines,
// we must protect them because they're reporting that as bug...
c.writerMu.Lock()
@ -266,6 +266,7 @@ func (c *connection) write(websocketMessageType int, data []byte) {
// if failed then the connection is off, fire the disconnect
c.Disconnect()
}
return err
}
// writeDefault is the same as write but the message type is the configured by c.messageType
@ -305,7 +306,11 @@ func (c *connection) startPinger() {
// wait for each tick
<-c.pinger.C
// try to ping the client, if failed then it disconnects
c.write(websocket.PingMessage, []byte{})
err := c.write(websocket.PingMessage, []byte{})
if err!=nil{
//must stop to exit the loop and finish the go routine
break
}
}
}()
}