mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
Add websocket TCP write timeouts (#18988)
Add 3 second write timeout to writes. This will make dead TCP connections terminate in a reasonable time. Fixes writes blocking for reconnection.
This commit is contained in:
parent
ebc6c9b498
commit
22687c1f50
@ -179,6 +179,7 @@ const (
|
||||
writeBufferSize = 16 << 10
|
||||
defaultDialTimeout = 2 * time.Second
|
||||
connPingInterval = 10 * time.Second
|
||||
connWriteTimeout = 3 * time.Second
|
||||
)
|
||||
|
||||
type connectionParams struct {
|
||||
@ -600,6 +601,10 @@ func (c *Connection) sendMsg(conn net.Conn, msg message, payload msgp.MarshalSiz
|
||||
if c.outgoingBytes != nil {
|
||||
c.outgoingBytes(int64(len(dst)))
|
||||
}
|
||||
err = conn.SetWriteDeadline(time.Now().Add(connWriteTimeout))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return wsutil.WriteMessage(conn, c.side, ws.OpBinary, dst)
|
||||
}
|
||||
|
||||
@ -1104,6 +1109,11 @@ func (c *Connection) handleMessages(ctx context.Context, conn net.Conn) {
|
||||
return
|
||||
}
|
||||
PutByteBuffer(toSend)
|
||||
err = conn.SetWriteDeadline(time.Now().Add(connWriteTimeout))
|
||||
if err != nil {
|
||||
logger.LogIf(ctx, fmt.Errorf("conn.SetWriteDeadline: %w", err))
|
||||
return
|
||||
}
|
||||
_, err = buf.WriteTo(conn)
|
||||
if err != nil {
|
||||
logger.LogIf(ctx, fmt.Errorf("ws write: %w", err))
|
||||
@ -1143,6 +1153,11 @@ func (c *Connection) handleMessages(ctx context.Context, conn net.Conn) {
|
||||
return
|
||||
}
|
||||
// buf is our local buffer, so we can reuse it.
|
||||
err = conn.SetWriteDeadline(time.Now().Add(connWriteTimeout))
|
||||
if err != nil {
|
||||
logger.LogIf(ctx, fmt.Errorf("conn.SetWriteDeadline: %w", err))
|
||||
return
|
||||
}
|
||||
_, err = buf.WriteTo(conn)
|
||||
if err != nil {
|
||||
logger.LogIf(ctx, fmt.Errorf("ws write: %w", err))
|
||||
|
Loading…
Reference in New Issue
Block a user