-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement configurable ping timeout for nhooyr.io/websocket
#113
Conversation
6decc55
to
67a106f
Compare
- added `pingTimeout time.Duration` to `internal/nhooyr.io/websocket/conn.go`'s `Conn struct` - implemented `SetPingTimeout`, following how `nhooyr.io/websocket` exposes configurable conn values - if `conn`'s `pingTimeout` is nonpositive, then use `handleControl`'s 5 second timeout https://github.com/xmidt-org/xmidt-agent/blob/78dffe0cad394ab82f581940e3a8117f04941077/internal/nhooyr.io/websocket/read.go#L301
67a106f
to
924a2c6
Compare
nhooyr.io/websocket
#88nhooyr.io/websocket
#83
nhooyr.io/websocket
#83nhooyr.io/websocket
writeErr := c.writeControl(context.Background(), opClose, p) | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancel() | ||
|
||
writeErr := c.writeControl(ctx, opClose, p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c.writeControl
uses the 5 seconds default timeout
ctx, cancel := context.WithTimeout(ctx, time.Second*5) | ||
defer cancel() | ||
|
||
_, err := c.writeFrame(ctx, true, false, opcode, p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this default time.Second*5
is only used here https://github.com/xmidt-org/xmidt-agent/pull/113/files#r1591363724
// SetPingTimeout sets the maximum time allowed between PINGs for the connection | ||
// before the connection is closed. | ||
// Nonpositive PingTimeout will default to handleControl's 5 second timeout. | ||
func (c *Conn) SetPingTimeout(d time.Duration) { | ||
c.pingTimeout = d | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
following how nhooyr.io/websocket
exposes configurable conn values
if ctx.Err() != nil { | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in case of timeouts/cancels
implements #83 #88
pingTimeout
tointernal/nhooyr.io/websocket/conn.go
'sConn struct
.