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

WebSocket reconnect - ws provider will miss some events. #3491

Closed
VladoDemcak opened this issue Apr 28, 2020 · 3 comments · Fixed by #3502
Closed

WebSocket reconnect - ws provider will miss some events. #3491

VladoDemcak opened this issue Apr 28, 2020 · 3 comments · Fixed by #3502
Labels
1.x 1.0 related issues Investigate

Comments

@VladoDemcak
Copy link
Contributor

Web3 v1.2.7

We are testing new web3 reconnect feature which has been added in v1.2.7. It works fine but there is one problem we have found.

Setup. WS provider with auto reconnect = true and 3sec delay.

  1. We send events 1,2,3,4
  2. close WS, now wait delay 3 sec for reconnect
  3. Within the delay gap - let's send events 5 and 6
  4. WS will reconnect after 3 sec delay and start subscription again. However we will miss events 5 and 6.

We can set small delay but I think there might be still a time gap where we can miss some events.

We tried to workaround this with keeping fromBlock once we processed an event and when ws is reconnected we recreated subscriptions. but web3's requestManager will create it's own subscriptions https://github.com/ethereum/web3.js/blob/v1.2.7/packages/web3-core-requestmanager/src/index.js#L113 and we will have 2 separated subscriptions. so we would process one event twice.

Image below is showing what was happening in the test case.

npm run server -> without WS reconnection we have all events
npm run listen -> WS has been closed and reconnected. we missed events from blocks: 3255 and 3256
npm run send -> you can see when we sent BasicEvents and compare timestamps.

The red rectangles show the "black hole".

image

You can use again my https://github.com/VladoDemcak/eth-subscribe-debug repository with steps how to reproduce the issue.

@VladoDemcak VladoDemcak changed the title WebSocket reconnect - ws provider miss some events. WebSocket reconnect - ws provider will miss some events. Apr 28, 2020
@cgewecke
Copy link
Collaborator

@VladoDemcak Ah interesting, that makes sense. Will look into this.

@cgewecke cgewecke added 1.x 1.0 related issues Investigate labels Apr 28, 2020
VladoDemcak pushed a commit to VladoDemcak/web3.js that referenced this issue Apr 28, 2020
@VladoDemcak
Copy link
Contributor Author

VladoDemcak commented Apr 28, 2020

@cgewecke Thanks. I had few minutes to play with this.

Honestly I didn't have time to analyze web3-core-subscription but I wanted to try to add a checkpoint for reconnection. You can look at my PR https://github.com/ethereum/web3.js/pull/3493/files

I tried to run web3 mocha tests. Result: 2731 passing (1m) 1 pending. so maybe the "fix" caused the test failure.
if u will need any help please let me know. fingers crossed.

@Welziewagers2015
Copy link

Welziewagers2015 commented Apr 28, 2020 via email

@ryanio ryanio mentioned this issue May 8, 2020
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Investigate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants