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

Connection closed by certstream-server due to missing ping packets #7

Open
heipei opened this issue Feb 14, 2020 · 8 comments · May be fixed by #8
Open

Connection closed by certstream-server due to missing ping packets #7

heipei opened this issue Feb 14, 2020 · 8 comments · May be fixed by #8

Comments

@heipei
Copy link
Contributor

heipei commented Feb 14, 2020

I discovered that using certstream-js (and any other websocket client), the connection by certstream-server is closed if there are no ping/heartbeat packets sent by the client.

certstream-js doesn't send any and also doesn't auto-reconnect so this effectively stop consumption. I didn't want to file this as an issue against certstream-server since I believe certstream-server/cowboy is behaving correctly. I don't have a workaround right now, just posting this for visibility.

@scharc
Copy link

scharc commented Feb 22, 2020

Any news on this?

@Fitblip
Copy link
Member

Fitblip commented Feb 22, 2020

Hi there, sorry about the delay. I don't have time to implement this unfortunately, but I'll happily review a PR to add these client pings.

@mawalu mawalu linked a pull request Dec 24, 2020 that will close this issue
@tasinet
Copy link

tasinet commented Aug 22, 2021

PR looks good.

You can also fix this in your client script:

const client = new CertStreamClient(function(message){
    console.log(message);
});
 
client.connect();

setInterval(() => client.ws.ping(), 30000);

@RedSpid3r
Copy link

PR looks good.

You can also fix this in your client script:

const client = new CertStreamClient(function(message){
    console.log(message);
});
 
client.connect();

setInterval(() => client.ws.ping(), 30000);

For me this did not work, I was getting errors:

2021-09-09T13:10:39: Connecting to wss://certstream.calidog.io/...
2021-09-09T13:10:39: Connection established to certstream! Waiting for messages...
2021-09-09T13:16:24: /home/**********/node_modules/ws/lib/WebSocket.js:360
2021-09-09T13:16:24:       throw new Error('not opened');
2021-09-09T13:16:24:       ^
2021-09-09T13:16:24:
2021-09-09T13:16:24: Error: not opened
2021-09-09T13:16:24:     at WebSocket.ping (/home/**********/node_modules/ws/lib/WebSocket.js:313:13)
2021-09-09T13:16:24:     at Timeout._onTimeout (/home/**********/**********/certStream.js:171:42)
2021-09-09T13:16:24:     at listOnTimeout (internal/timers.js:554:17)
2021-09-09T13:16:24:     at processTimers (internal/timers.js:497:7)

@tasinet
Copy link

tasinet commented Sep 9, 2021

For me this did not work, I was getting errors:

2021-09-09T13:10:39: Connecting to wss://certstream.calidog.io/...
2021-09-09T13:10:39: Connection established to certstream! Waiting for messages...
2021-09-09T13:16:24: /home/**********/node_modules/ws/lib/WebSocket.js:360
2021-09-09T13:16:24:       throw new Error('not opened');

This happens when your websocket has been closed (or it wasn't open, but from your timestamps I can rule that out).

You can see what is happening by registering these event handlers:

client.connect(); // must happen first for client.ws to be created

setInterval(() => client.ws.ping(), 30000);

client.ws.on('terminate',  (...args) => console.log('terminate', ...args));

client.ws.on('close',  (...args) => console.log('close', ...args));

client.ws.on('error', (...args) => console.log('error', ...args) );

when your websocket is closed you need to clear the ping setInterval like this:

// setup like this; setInterval returns a numeric ID identifying the interval
const pingInterval = setInterval(() => client.ws.ping(), 30000);

// later when you want to cancel it:
clearInterval(pingInterval)

and set one up again when you re-connect.

@RedSpid3r
Copy link

RedSpid3r commented Sep 11, 2021

Thanks for the reply. I added the above handlers and now I can see:

2021-09-10T04:02:29: Connecting to wss://certstream.calidog.io/...
2021-09-10T04:02:29: Connection established to certstream! Waiting for messages...
2021-09-10T07:07:13: close 1006

I see that 1006 is "Abnormal Closure" but I don't see any errors in my logs

@ImLunaHey
Copy link

Did anyone resolve this? Using the .ping() method and/or sending a ping packet manually doesn't seem to make a difference with this.

No matter what I get disconnected after ~60s.

@gcleaves
Copy link

@ImLunaHey From what I can tell regular disconnects are fairly standard with certstream. If you use the Python command line tool you'll notice that it disconnect and reconnects often.

I think the missing piece with the node library is the automatic reconnection. I faced this by watching the 'close' event and reconnecting.

client.ws.on('close', function() {
    console.log("CLOSE");
    // reconnect logic
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants