diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index ebc087136..8877d31ec 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -23,6 +23,8 @@ program](https://hackerone.com/tendermint). ### 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] [\#4406](https://github.com/tendermint/tendermint/pull/4406) Fix issue with multiple subscriptions on the websocket (@antho1404) diff --git a/rpc/core/events.go b/rpc/core/events.go index 2a4d042fc..165aa6e54 100644 --- a/rpc/core/events.go +++ b/rpc/core/events.go @@ -38,6 +38,8 @@ func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, er return nil, err } + // Capture the current ID, since it can change in the future. + subscriptionID := ctx.JSONReq.ID go func() { for { select { @@ -46,7 +48,7 @@ func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, er ctx.WSConn.TryWriteRPCResponse( rpctypes.NewRPCSuccessResponse( ctx.WSConn.Codec(), - ctx.JSONReq.ID, + subscriptionID, resultEvent, )) case <-sub.Cancelled(): @@ -59,7 +61,7 @@ func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, er } ctx.WSConn.TryWriteRPCResponse( rpctypes.RPCServerError( - ctx.JSONReq.ID, + subscriptionID, fmt.Errorf("subscription was cancelled (reason: %s)", reason), )) }