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

This commit is contained in:
Michael FIG
2020-02-29 13:22:19 -08:00
committed by GitHub
parent c5fe7334dc
commit 3f18e22c96
2 changed files with 6 additions and 2 deletions

View File

@@ -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)

View File

@@ -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),
))
}