Skip to content

Commit

Permalink
Remove ReadDuration websocket connection param
Browse files Browse the repository at this point in the history
Disconnects clients automatically after 30 seconds if there is no
request. This is problematic for subscriptions, where a client may never
make more than one request even if multiple responses are sent.
  • Loading branch information
joshklop committed Jul 25, 2023
1 parent 2da7568 commit 43d9a40
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions jsonrpc/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,12 @@ type WebsocketConnParams struct {
ReadLimit int64
// Maximum time to write a message.
WriteDuration time.Duration
// Maximum time to read a message.
ReadDuration time.Duration
}

func DefaultWebsocketConnParams() *WebsocketConnParams {
return &WebsocketConnParams{
ReadLimit: 32 * 1024 * 1024,
WriteDuration: 5 * time.Second,
ReadDuration: 30 * time.Second,
}
}

Expand All @@ -131,7 +128,7 @@ func newWebsocketConn(conn *websocket.Conn, rpc *Server, params *WebsocketConnPa
func (wsc *websocketConn) ReadWriteLoop(ctx context.Context) error {
for {
// Read next message from the client.
_, r, err := wsc.Read(ctx)
_, r, err := wsc.conn.Read(ctx)
if err != nil {
return err
}
Expand All @@ -155,12 +152,6 @@ func (wsc *websocketConn) ReadWriteLoop(ctx context.Context) error {
}
}

func (wsc *websocketConn) Read(ctx context.Context) (websocket.MessageType, []byte, error) {
readCtx, readCancel := context.WithTimeout(ctx, wsc.params.ReadDuration)
defer readCancel()
return wsc.conn.Read(readCtx)
}

func (wsc *websocketConn) Write(ctx context.Context, msg []byte) error {
writeCtx, writeCancel := context.WithTimeout(ctx, wsc.params.WriteDuration)
defer writeCancel()
Expand Down

0 comments on commit 43d9a40

Please sign in to comment.