From 43d9a402aa336c391ddb53a6c5e036504298f56f Mon Sep 17 00:00:00 2001 From: Josh Klopfenstein Date: Mon, 24 Jul 2023 14:28:16 -0700 Subject: [PATCH] Remove ReadDuration websocket connection param 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. --- jsonrpc/websocket.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/jsonrpc/websocket.go b/jsonrpc/websocket.go index d98010d5fb..4b05f71fba 100644 --- a/jsonrpc/websocket.go +++ b/jsonrpc/websocket.go @@ -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, } } @@ -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 } @@ -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()