WebsocketProvider: Incorrect response when duplicate IDs #1510
Labels
1.x
1.0 related issues
Enhancement
Includes improvements or optimizations
Stale
Has not received enough activity
Summary
The WebsocketProvider stores callbacks by ID, which it then looks up after receiving the response. However, there may be multiple consumers of the WebsocketProvider that are unaware of each other and duplicate IDs, leading to incorrect responses.
Long story
I ran into this issue while building an app using
truffle-contract
, which comes bundled with it's own version of web3. I also use my own version of web3 for making calls directly.The problem comes from the two versions of web3 not sharing the same RequestManager, which is responsible for generating ID numbers. This results in duplicate IDs and incorrect responses.
Workaround
This issue can be fixed by generating two different WebsocketProviders, passing one to instances of truffle-contract, and using the other for web3.
Proposed change
ID numbers in the JSONRPC are essentially meaningless. The WebsocketProvider could replace the ID provided in a data payload with a random integer.
The text was updated successfully, but these errors were encountered: