mirror of
https://github.com/kataras/iris.git
synced 2025-02-09 02:34:55 +01:00
Merge pull request #788 from jerson/patch-3
Websocket: fixed memory leak on startPinger Former-commit-id: 9c4277f6eda39c52c02942e1311ec6fa1ecf8974
This commit is contained in:
commit
cddce4de5b
|
@ -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
|
// write writes a raw websocket message with a specific type to the client
|
||||||
// used by ping messages and any CloseMessage types.
|
// 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,
|
// for any-case the app tries to write from different goroutines,
|
||||||
// we must protect them because they're reporting that as bug...
|
// we must protect them because they're reporting that as bug...
|
||||||
c.writerMu.Lock()
|
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
|
// if failed then the connection is off, fire the disconnect
|
||||||
c.Disconnect()
|
c.Disconnect()
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeDefault is the same as write but the message type is the configured by c.messageType
|
// 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
|
// wait for each tick
|
||||||
<-c.pinger.C
|
<-c.pinger.C
|
||||||
// try to ping the client, if failed then it disconnects
|
// 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user