From 21d8c5a765c334ce7e52f9b3c82580340815485f Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 3 Mar 2020 17:02:19 +0400 Subject: [PATCH 1/4] rpc: create buffered subscriptions on /subscribe buffer size: 100 Closes #3935 --- rpc/core/events.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rpc/core/events.go b/rpc/core/events.go index 165aa6e54fd..4d87a6797b2 100644 --- a/rpc/core/events.go +++ b/rpc/core/events.go @@ -12,6 +12,11 @@ import ( rpctypes "github.com/tendermint/tendermint/rpc/lib/types" ) +const ( + // Buffer on the Tendermint (server) side to allow some slowness in clients. + subCap = 100 +) + // Subscribe for events via WebSocket. // More: https://docs.tendermint.com/master/rpc/#/Websocket/subscribe func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, error) { @@ -33,7 +38,7 @@ func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, er subCtx, cancel := context.WithTimeout(ctx.Context(), SubscribeTimeout) defer cancel() - sub, err := eventBus.Subscribe(subCtx, addr, q) + sub, err := eventBus.Subscribe(subCtx, addr, q, subCap) if err != nil { return nil, err } From 6f6c1b6425d4dab54c569086e9ffa9f73fc2ee97 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 3 Mar 2020 17:03:57 +0400 Subject: [PATCH 2/4] update changelog --- CHANGELOG_PENDING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index f85b63307e3..3bd983a0e61 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -24,6 +24,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi ### BUG FIXES: +- [rpc] \#3935 Create buffered subscriptions on `/subscribe` (@melekes) - [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) From 106a59fde35fb247177217a8395beb23f6cad366 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 5 Mar 2020 12:04:56 +0400 Subject: [PATCH 3/4] rename subCap to subBufferSize --- rpc/core/events.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rpc/core/events.go b/rpc/core/events.go index 4d87a6797b2..7802f160e60 100644 --- a/rpc/core/events.go +++ b/rpc/core/events.go @@ -14,7 +14,7 @@ import ( const ( // Buffer on the Tendermint (server) side to allow some slowness in clients. - subCap = 100 + subBufferSize = 100 ) // Subscribe for events via WebSocket. @@ -38,7 +38,7 @@ func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, er subCtx, cancel := context.WithTimeout(ctx.Context(), SubscribeTimeout) defer cancel() - sub, err := eventBus.Subscribe(subCtx, addr, q, subCap) + sub, err := eventBus.Subscribe(subCtx, addr, q, subBufferSize) if err != nil { return nil, err } From 097f15b02aa2d6960c830268ab75fa1b9efcabad Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 5 Mar 2020 12:14:17 +0400 Subject: [PATCH 4/4] add docs --- rpc/core/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rpc/core/README.md b/rpc/core/README.md index d767c5f7169..f62d2dbf445 100644 --- a/rpc/core/README.md +++ b/rpc/core/README.md @@ -5,3 +5,14 @@ Requests that return multiple items will be paginated to 30 items by default. You can specify further pages with the ?page parameter. You can also set a custom page size up to 100 with the ?per_page parameter. + +## Subscribing to events + +The user can subscribe to events emitted by Tendermint, using `/subscribe`. If +the maximum number of clients is reached or the client has too many +subscriptions, an error will be returned. The subscription timeout is 5 sec. +Each subscription has a buffer to accommodate short bursts of events or some +slowness in clients. If the buffer gets full, the subscription will be canceled +("client is not pulling messages fast enough"). If Tendermint exits, all +subscriptions are canceled ("Tendermint exited"). The user can unsubscribe +using either `/unsubscribe` or `/unsubscribe_all`.