Browse Source

rpc: fix issue with multiple subscriptions (#4406)

Using the WebSocket server, when the same client calls multiple time the subscribe method, only the last subscription receives all the events of the previous ones.

example:

    subscription1 = tm.event = 'NewBlock'
    subscription2 = tm.event = 'Tx'

In this case, subscription2 will receive the new blocks but subscription1 will not.

This came from the WebSocket handler that had the declaration of the rpcrequest moved and so overridden for every request and given in the JSONReq client context (so the id of the subscription was not the right one).

This fixes the issue by simply declaring the rpcrequest inside the loop so every request will create a new object without overwriting the previous one.
pull/4423/head
Anthony 5 years ago
committed by GitHub
parent
commit
5ea1ff94d1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions
  1. +2
    -0
      CHANGELOG_PENDING.md
  2. +2
    -3
      rpc/lib/server/ws_handler.go

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -20,3 +20,5 @@ program](https://hackerone.com/tendermint).
### IMPROVEMENTS:
### BUG FIXES:
- [rpc] [\#4406](https://github.com/tendermint/tendermint/pull/4406) Fix issue with multiple subscriptions on the websocket (@antho1404)

+ 2
- 3
rpc/lib/server/ws_handler.go View File

@ -299,8 +299,6 @@ func (wsc *wsConnection) Context() context.Context {
// Read from the socket and subscribe to or unsubscribe from events
func (wsc *wsConnection) readRoutine() {
var request types.RPCRequest
defer func() {
if r := recover(); r != nil {
err, ok := r.(error)
@ -308,7 +306,7 @@ func (wsc *wsConnection) readRoutine() {
err = fmt.Errorf("WSJSONRPC: %v", r)
}
wsc.Logger.Error("Panic in WSJSONRPC handler", "err", err, "stack", string(debug.Stack()))
wsc.WriteRPCResponse(types.RPCInternalError(request.ID, err))
wsc.WriteRPCResponse(types.RPCInternalError(types.JSONRPCIntID(-1), err))
go wsc.readRoutine()
}
}()
@ -339,6 +337,7 @@ func (wsc *wsConnection) readRoutine() {
return
}
var request types.RPCRequest
err = json.Unmarshal(in, &request)
if err != nil {
wsc.WriteRPCResponse(types.RPCParseError(errors.Wrap(err, "error unmarshaling request")))


Loading…
Cancel
Save