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

fix: wrap _rpcWebSocketGeneration around when about to overflow #28428

Merged
merged 1 commit into from
Oct 17, 2022
Merged

fix: wrap _rpcWebSocketGeneration around when about to overflow #28428

merged 1 commit into from
Oct 17, 2022

Conversation

steveluscher
Copy link
Contributor

@steveluscher steveluscher commented Oct 17, 2022

Problem

It's conceivable that someone could open up so many WebSocket connections (ie. in a long running Node process) so as to exhaust this index. JavaScript integers, after all, have a maximum value of Number.MAX_SAFE_INTEGER.

Upon hearing a report of someone with a script that works from Saturday to Thursday but then crashes with the dreaded infinite recursion bug (see solana-labs/solana-web3.js#1106) I immediately thought that this index might be overflowing, essentially pinning it to a constant value from Number.MAX_SAFE_INTEGER + 1 onward.

Summary of Changes

Wrap the index back around to 0 after hitting Number.MAX_SAFE_INTEGER.

Addresses solana-labs/solana-web3.js#1106. Closes #28426.

@steveluscher steveluscher marked this pull request as ready for review October 17, 2022 06:32
@steveluscher steveluscher added the javascript Pull requests that update Javascript code label Oct 17, 2022
@steveluscher steveluscher self-assigned this Oct 17, 2022
@steveluscher steveluscher merged commit 5d17215 into solana-labs:master Oct 17, 2022
@steveluscher steveluscher deleted the wraparound-websocket-generation branch October 17, 2022 06:33
@steveluscher
Copy link
Contributor Author

I know that 2^53 is a lot, and that 2^53ms is a whole lot of days' worth of time, but stranger things have happened. Imagine if this actually fixed something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[web3.js] Protect against overflowing _rpcWebSocketGeneration
1 participant