-
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: improve ws.conn handling #57
Conversation
cddd22e
to
9b0b578
Compare
internal/websocket/e2e_test.go
Outdated
@@ -44,14 +48,19 @@ func TestEndToEnd(t *testing.T) { | |||
require.NoError(err) | |||
|
|||
mt, got, err := c.Read(ctx) | |||
// server will halt until the websocket closes resulting in a EOF | |||
if finished && errors.Is(err, io.EOF) { |
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.
No need to use errors.Is
here. In fact, you really shouldn't. io.Reader.Read
is documented as returning exactly io.EOF
in this case. I realize the linter will complain, which is why I hate our linter :)
8d1fa9b
to
3dd1841
Compare
ctx, cancel := context.WithTimeout(r.Context(), 2000000*time.Millisecond) | ||
ctx, cancel := context.WithTimeout(r.Context(), 200*time.Millisecond) |
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 was a silly artifact of some test debugging code in a previous pr
3dd1841
to
47faddb
Compare
} | ||
|
||
// Stop stops the websocket connection. | ||
func (ws *Websocket) Stop() { | ||
ws.m.Lock() | ||
// Avoid the overhead of the close handshake. | ||
ws.conn.Close(nhws.StatusNormalClosure, "") |
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.
looks like nhooyr.io/websocket's websocket doesn't like it when you use its own nhws.StatusNormalClosure to close the socket... I was expecting a normal EOF:
Received unexpected error:
failed to get reader: received close frame: status = StatusNormalClosure and reason = ""
mt, got, err := c.Read(ctx) |
Error Trace: /Users/odc/Documents/GitHub/xmidt-org/xmidt-agent/internal/websocket/e2e_test.go:56
/Users/odc/go/pkg/mod/golang.org/[email protected]/src/net/http/server.go:2136
/Users/odc/go/pkg/mod/golang.org/[email protected]/src/net/http/server.go:2938
/Users/odc/go/pkg/mod/golang.org/[email protected]/src/net/http/server.go:2009
/Users/odc/go/pkg/mod/golang.org/[email protected]/src/runtime/asm_amd64.s:1650
Error: Received unexpected error:
failed to get reader: received close frame: status = StatusNormalClosure and reason = ""
Test: TestEndToEnd
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.
I would assume nhws.StatusNormalClosure
would trigger a io.EOF
and not a unexpected error
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.
looks like nhooyr.io/websocket's Reader
doesn't return an io.EOF
for a StatusNormalClosure
(status code 1000).
#57 (comment)
just a fyi
47faddb
to
54bb265
Compare
ad58af4
to
d5f5710
Compare
Doesn't include
func (ws *websocket) Send()
update