Browse Source

rpc: keep the original subscription "id" field when new RPCs come in (#4493)

pull/4509/head
Michael FIG 5 years ago
committed by GitHub
parent
commit
3f18e22c96
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions
  1. +2
    -0
      CHANGELOG_PENDING.md
  2. +4
    -2
      rpc/core/events.go

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -23,6 +23,8 @@ program](https://hackerone.com/tendermint).
### BUG FIXES: ### BUG FIXES:
- [rpc] [\#4493](https://github.com/tendermint/tendermint/pull/4493) Keep the original subscription "id" field when new RPCs come in (@michaelfig)
- [rpc] [\#4437](https://github.com/tendermint/tendermint/pull/4437) Fix tx_search pagination with ordered results (@erikgrinaker) - [rpc] [\#4437](https://github.com/tendermint/tendermint/pull/4437) Fix tx_search pagination with ordered results (@erikgrinaker)
- [rpc] [\#4406](https://github.com/tendermint/tendermint/pull/4406) Fix issue with multiple subscriptions on the websocket (@antho1404) - [rpc] [\#4406](https://github.com/tendermint/tendermint/pull/4406) Fix issue with multiple subscriptions on the websocket (@antho1404)

+ 4
- 2
rpc/core/events.go View File

@ -38,6 +38,8 @@ func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, er
return nil, err return nil, err
} }
// Capture the current ID, since it can change in the future.
subscriptionID := ctx.JSONReq.ID
go func() { go func() {
for { for {
select { select {
@ -46,7 +48,7 @@ func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, er
ctx.WSConn.TryWriteRPCResponse( ctx.WSConn.TryWriteRPCResponse(
rpctypes.NewRPCSuccessResponse( rpctypes.NewRPCSuccessResponse(
ctx.WSConn.Codec(), ctx.WSConn.Codec(),
ctx.JSONReq.ID,
subscriptionID,
resultEvent, resultEvent,
)) ))
case <-sub.Cancelled(): case <-sub.Cancelled():
@ -59,7 +61,7 @@ func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, er
} }
ctx.WSConn.TryWriteRPCResponse( ctx.WSConn.TryWriteRPCResponse(
rpctypes.RPCServerError( rpctypes.RPCServerError(
ctx.JSONReq.ID,
subscriptionID,
fmt.Errorf("subscription was cancelled (reason: %s)", reason), fmt.Errorf("subscription was cancelled (reason: %s)", reason),
)) ))
} }


Loading…
Cancel
Save