Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: create buffered subscriptions on /subscribe #4521

Merged
merged 6 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, but do you want to make this a link like the other items in this list?

Copy link
Contributor

@tac0turtle tac0turtle Mar 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically this is the correct way according to the contributing.md and then there is a script to add all the links prior to release. People have been putting links recently, I guess we should decide on one way or the other?

https://github.com/tendermint/tendermint/blob/master/CONTRIBUTING.md#changelog

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, there's a script for that

- [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)
Expand Down
11 changes: 11 additions & 0 deletions rpc/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
7 changes: 6 additions & 1 deletion rpc/core/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
subBufferSize = 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) {
Expand All @@ -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, subBufferSize)
if err != nil {
return nil, err
}
Expand Down