Skip to content

Commit

Permalink
Fix zero writeTimeout cause write failure
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Feb 17, 2023
1 parent e903dc0 commit 3b183c6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,11 @@ func (c *Client) handleReconnect() {

func (c *Client) writeMessage(buf []byte, writeTimeout time.Duration) error {
c.lock.Lock()
c.conn.SetWriteDeadline(time.Now().Add(writeTimeout))
if writeTimeout == 0 {
c.conn.SetWriteDeadline(zeroTime)
} else {
c.conn.SetWriteDeadline(time.Now().Add(writeTimeout))
}
err := c.conn.WriteMessage(websocket.BinaryMessage, buf)
c.lock.Unlock()
if err != nil {
Expand Down

0 comments on commit 3b183c6

Please sign in to comment.