Skip to content
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

chore(x): return io.EOF on WS disconnect #364

Merged
merged 6 commits into from
Jan 30, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions x/websocket/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ func newEndpoint[ConnType net.Conn](urlStr string, sd transport.StreamDialer, ws
}, nil
}

// WrapConn wraps a [websocket.Conn] from the Gorilla library into a
// [transport.StreamConn].
func WrapConn(wsConn *websocket.Conn) transport.StreamConn {
sbruens marked this conversation as resolved.
Show resolved Hide resolved
return &gorillaConn{wsConn: wsConn}
}

type gorillaConn struct {
wsConn *websocket.Conn
writeErr error
Expand Down Expand Up @@ -155,6 +161,9 @@ func (c *gorillaConn) Read(buf []byte) (int, error) {
return 0, c.readErr
}
if err != nil {
if _, ok := err.(*websocket.CloseError); ok {
sbruens marked this conversation as resolved.
Show resolved Hide resolved
return 0, io.EOF
}
return 0, err
}
if msgType != websocket.BinaryMessage {
Expand Down