Configure the channel pool to open a new channel when all of the currently open channels reach 100 subscriptions each #3380
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When you make ‘too many’ subscriptions over a single channel/connection/socket, RPC providers will throw errors. The idea behind this PR is to set the default subscriptions-per-channel low enough so as to avoid running afoul of even the most restrictive provider's limit.
This was determined experimentally by hitting various nodes with this script.
api.mainnet-beta.solana.com
): 100The ground truth is this:
The right thing to do here would be for providers not to kill the channels, but rather to respond to the suscription request with a JSON-RPC response, of the form:
If everyone did that, and we all decided on an error code in the range -32000 to -32099, as demanded by what the JSON-RPC spec says about errors, then the channel pool could catch that error to know when a new channel needed to be added to the pool. Because they don't, we have to participate in this tragedy of the commons, and hardcode the limit to 100 so that people using the public endpoint will not get caught off-guard by the limit.
Note
There might actually be two kinds of errors: ‘I can't give you this subscription over this channel, open a new one’ and ‘I can't give you this subscription over any channel, please stop opening subscriptions.’
cc/ @linuskendall, @WilfredAlmeida, @vovkman