Infura stop about 1 hour

How can I prevent connection idle after subscribe about 1 hour?

Can you provide more information on what you are trying to do?

I’m trying to get newBlockHeaders using web3js with infura websocket! but it’s only work about 1 hour then the connect end! How can I send pings or reconnect to infura websocket wss://, thanks

Are you receiving an error or any information (i.e. response) when the websocket connection closes?

var provider = new Web3.providers.WebsocketProvider("wss://", 30000)
var web3 = new Web3(provider)

provider.on("connect", ()=>{
        web3.eth.subscribe("newBlockHeaders", (err, block) => {

provider.on("end", ()=>{
        console.log("provider end")

that’s my code!
Provider end log after subscribe newBlockHeaders ilde 1hour.

Can you provide the end log?

The same problem. Sometimes connection stops after one hour sometimes after 4. I try to reconnect when it stops, but finally the connection shuts down.
Also use web3.js library and NodeJs. Connection link: " wss://"

Hi, i’m using a trick. set socket disconnect per 1hour. Then restart socket again… like this
function start(){
web3 = new Web3(“wss://…”)

web3.on(“end”, function(){

}, 60 * 60 * 1000)

// something like this… hope to help you

Hi I`m using the below code to send ping, but not working.
Connection stops after about one hour.

const websocket = new Web3.providers.WebsocketProvider(wss://;
websocket.connection._client.config.keepalive = true;
websocket.connection._client.config.keepaliveInterval = 60000;
const web3Websocket = new Web3(websocket);

I’m having the same issue. I have tried adding a ping at minute interval, both as a websocket ping frame and as a eth_getBlockByNumber call and both failed to keep the websocket open. I get an “EOF” error approximately an hour after I start the connection then have to reconnect. The disconnect occurs at almost exactly 1 hour 10 min intervals for me.

Is there a solution or workaround for this? I use it for long running eth_subscribe calls.

Any progress / ideas on the issue? Has anyone got it working for long-lasting ws subscriptions using go-ethereum client?

I have yet to solve the problem using go-ethereum. I reached out to the Infura folks and didn’t really get an answer. I did write a test client using the gorilla websockets package with a proper ping frame and it seemed to stay open past an hour. Problem with go-ethereum is that it uses the old x/net/websocket library which doesn’t support client pings. so i’ve been trying to figure out a workaround that still uses the go-ethereum library since I don’t want to rewrite all of that. Or submit a PR into go-ethereum that uses a library that supports ping frames.

I’m all for any other ideas that people might have to solve this on top of go-ethereum.

I ended up using Parity client - haven’t had time to debug / figure out ways to make it work with Infura node. So that’s that.

1 Like

We are experimenting the same behaviour, websocket disconnect around an hour :frowning:
Any idea about the solutions of this annoying issue, really its a big problem!

We have our DAPP in Amazon AWS infrastructure, This will have something to do???
@mike your help or comments on this please!

Hi @mike any insights about this?
Thank you very much por your time on this!

Can you send more info on your connection, what method you’re using, etc.?

We use this to connect:

const QoriManager = require('./contracts/QoriManager.json');
let provider = new Web3.providers.WebsocketProvider('wss://');
let web3 = new Web3(provider);
  .then(res => console.log('Websocket infura connection:', res))
  .catch(err => console.log('No connection', err));
const contract = new web3.eth.Contract(QoriManager.abi, contractAddress);

Our DAPP is in Amazon AWS LightSail server with 2 GB RAM, 1 vCPU, 60 GB SSD.
If you need some other details let me know, thanks for your kindly response.


The isListening() method returns whether a node is listening for peers, this uses the method, net_listening which is supported by our HTTPS endpoint if you need that information.

Can you try connecting using a different method to test your WSS connection?

Is it not possible to add some kind of a heartbeat so we dont have to reconnect unnecessarily after an hour, which we will just end up doing? It kind of defeats the purpose of disconnecting users after an hour (due to idle sessions), as we will just reconnect.

In general, we don’t encourage having idle connections. It takes up resources that are not being used for anything. The idle connection also can be seen as a indication of something going wrong. The backend ethereum clients have stability issues related to subscription and filters where the node is ‘healthy’ but subscriptions and filters stop responding. The only thing you can do at that point, is to reconnect. We realize this is a problem for our users and are in the process of upgrading our subscriptions to be less client dependent. The ‘newHeads’ subscription has been upgraded so you shouldn’t see a timeout issue with newHeads, and are also in the process of upgrading our log subscription.