Skip to content

Commit

Permalink
Use session write timeout instead of default ws write timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Jan 24, 2023
1 parent 9524c81 commit 9c3f5a3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,9 @@ func (c *Client) handleReconnect() {
}
}

func (c *Client) writeMessage(buf []byte) error {
func (c *Client) writeMessage(buf []byte, writeTimeout time.Duration) error {
c.lock.Lock()
c.conn.SetWriteDeadline(time.Now().Add(time.Duration(c.config.WsWriteTimeout) * time.Millisecond))
c.conn.SetWriteDeadline(time.Now().Add(writeTimeout))
err := c.conn.WriteMessage(websocket.BinaryMessage, buf)
c.lock.Unlock()
if err != nil {
Expand Down Expand Up @@ -828,7 +828,7 @@ func (c *Client) sendReceipt(prevSignature []byte) error {
return err
}

return c.writeMessage(buf)
return c.writeMessage(buf, time.Duration(c.config.WsWriteTimeout)*time.Millisecond)
}

// Send sends bytes or string data to one or multiple destinations with an
Expand Down Expand Up @@ -1119,7 +1119,7 @@ func (c *Client) sendTimeout(dests []string, payload *payloads.Payload, encrypte
return err
}

err = c.writeMessage(buf)
err = c.writeMessage(buf, writeTimeout)
if err != nil {
return err
}
Expand Down

0 comments on commit 9c3f5a3

Please sign in to comment.