Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Reconnect on Websocket Drop #1558

@Plinpod

Description

@Plinpod

Hello,

I am making a websocket connection to Infura Ropsten
wss://ropsten.infura.io/ws

and then making contract event subscription like so
contract.events.MyEvent() .on('data', function(event) { console.log('Event Generated', data) }) .on('error', function(error) { console.log('Event Error', error) })

Infuras websockets seem to be unstable and drop randomly. Unfortunately the websocket drops silently in the background and my event never receives the error. My app just continues to work and stops receiving event data.

I can tell that websocket drops by running setInterval on
web3.eth.net.isListening()

Is there a graceful way to catch the websocket drop and reconnect immediately? If not what is a safe interval to run isListening on?

Thanks!

Metadata

Metadata

Assignees

Labels

EnhancementIncludes improvements or optimizations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions