From dcde9d05a26ae9186caa22527e089383e17848a8 Mon Sep 17 00:00:00 2001 From: Gerson Alexander Pardo Gamez Date: Mon, 16 Oct 2017 17:54:17 -0500 Subject: [PATCH] Websocket: fixed memory leak on startPinger Former-commit-id: fe6162dd8914398e1333850950e1898e89e75005 --- websocket/connection.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/websocket/connection.go b/websocket/connection.go index a928b628..c0919eb2 100644 --- a/websocket/connection.go +++ b/websocket/connection.go @@ -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 + } } }() }