Browse Source

rpc: revert JSON-RPC/WebSocket response batching (#5378)

Revert the JSON-RPC/WebSocket response serialization format to the
standard way (i.e. a single RPC response per WebSocket text message) to
avoid breaking clients.

Serialization format changes will be discussed in an upcoming ADR.

Closes: #5373
pull/5362/head
Thane Thomson 4 years ago
committed by GitHub
parent
commit
309e29c245
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 33 deletions
  1. +2
    -33
      rpc/jsonrpc/server/ws_handler.go

+ 2
- 33
rpc/jsonrpc/server/ws_handler.go View File

@ -28,10 +28,6 @@ const (
defaultWSPingPeriod = (defaultWSReadWait * 9) / 10
)
var (
newline = []byte{'\n'}
)
// WebsocketManager provides a WS handler for incoming connections and passes a
// map of functions along with any additional params to new connections.
// NOTE: The websocket path is defined externally, e.g. in node/node.go
@ -439,40 +435,13 @@ func (wsc *wsConnection) writeRoutine() {
return
}
case msg := <-wsc.writeChan:
if err := wsc.baseConn.SetWriteDeadline(time.Now().Add(wsc.writeWait)); err != nil {
wsc.Logger.Error("Failed to set write deadline", "err", err)
return
}
jsonBytes, err := json.MarshalIndent(msg, "", " ")
if err != nil {
wsc.Logger.Error("Failed to marshal RPCResponse to JSON", "err", err)
continue
}
w, err := wsc.baseConn.NextWriter(websocket.TextMessage)
if err != nil {
wsc.Logger.Error("Can't get NextWriter", "err", err)
return
}
w.Write(jsonBytes) //nolint:errcheck //ignore error
// Add queued messages to the current websocket message.
n := len(wsc.writeChan)
for i := 0; i < n; i++ {
w.Write(newline) //nolint:errcheck //ignore error
msg = <-wsc.writeChan
jsonBytes, err = json.MarshalIndent(msg, "", " ")
if err != nil {
wsc.Logger.Error("Failed to marshal RPCResponse to JSON", "err", err)
continue
}
w.Write(jsonBytes) //nolint:errcheck //ignore error
}
if err := w.Close(); err != nil {
wsc.Logger.Error("Can't close NextWriter", "err", err)
if err = wsc.writeMessageWithDeadline(websocket.TextMessage, jsonBytes); err != nil {
wsc.Logger.Error("Failed to write response", "err", err, "msg", msg)
return
}
}


Loading…
Cancel
Save