-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Start incrementing jsonrpc message id from random number #5371
Start incrementing jsonrpc message id from random number #5371
Conversation
Your Render PR Server URL is https://web3-js-pr-5371.onrender.com. Follow its progress at https://dashboard.render.com/static/srv-cc1urp9gp3jp25qfgh6g. |
Pull Request Test Coverage Report for Build 2912165598
💛 - Coveralls |
Looks good 👍 is this something we want to consider for 4.x as well? |
messageId: 0 | ||
// This is the starting counter for the Jsonrpc.id. And, to insure staying in the safe range while incrementing later, | ||
// pick a random number between 0 and (the maximum safe integer minus the max unsigned 32 bit integer) | ||
messageId: Math.floor(Math.random() * (Number.MAX_SAFE_INTEGER - Math.pow( 2, 32 ))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a hunch that this will not fix the actual issue.
Responses get mixed up due to conflicting payload IDs
The response will still be mixed up if the payload Ids are conflicting, starting point does not matter and randomizing starting point would minimize but not fixed the problem.
For once instance of the web3
there will be no conflicting payload IDs in any case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per here: https://www.jsonrpc.org/specification
An identifier established by the Client that MUST contain a String, Number, or NULL value if included.
uuid
is already used in 1.x, maybe we could use it, also, for request id`s. We won't need a starting point and other libraries use numbers for ids.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there will be no issue if one instance is running and one library is used. And, yes, this solution will minimize the possibility of a conflict to some grade that is neglected but the possibility is still there.
But using a uuid (that would be handled as a string) instead of a number would be a breaking change. Even the tests for 1.x would need to be modified accordingly.
However, I proposed to handle this in a different way in v4.x as there we can do a breaking change by making the message id as a string that contains a UUID or another format. The new issue is here: #5373
And if you have a better suggestion to solve this in v1.x, please advise.
Thanks,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can proceed with this approach but considering it's not a permanent fix.
Also it does not matter if there is more than one library using the same id for the same endpoint. For the HTTP, the RPC server will be responding synchronously. For WS based RPC server it will be responding per connection. So if there are two libraries, both would be having different connections and that will not conflict the ids.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @nazarhussain ,
As you see this as "not a permanent fix", do you have a better suggestion for 1.x that does not cause a breaking change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if there are two libraries, both would be having different connections and that will not conflict the ids.
@nazarhussain I just wanted to note in my original report #5327, I saw a situation where two libraries were using the same connection, which resulted in an ID conflict. I'm not certain how this happened because I'm completely unfamilar with your codebase, but it's somehow possible.
In my case, it was eth-block-tracker
that was sending a message that somehow bypassed jsonrpc.js
but still was being processed by the same websocket connection that jsonrpc.js
was using, which resulted in a conflict.
Maybe someone more experienced than me could figure out how that happened? There might be another lurking bug there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR looks good, just added a comment in the conversation.
Description
Fixes #(issue)
Type of change
Checklist for 1.x:
npm run dtslint
with success and extended the tests and types if necessary.npm run test:cov
and my test cases cover all the lines and branches of the added code.npm run build
with success.dist/web3.min.js
in a browser.CHANGELOG.md
file in the root folder.Checklist for 4.x:
yarn
successfullyyarn lint
successfullyyarn build:web
successfullyyarn test:unit
successfullyyarn test:integration
successfullycompile:contracts
successfullyCHANGELOG.md
file in the packages I have edited.