question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request for repeated `heartbeat` option

See original GitHub issue

Some hosts are closing web socket connections if there is no traffic over a certain period. For example, heroku.

It would help if there was an option to keep the connection alive. This fork|commit has implemented a ping/pong like service. But a heartbeat need not be bi-directional.

Here is a (not well tested) workaround:

// pass the peer instance, and it will start sending heartbeats
var heartbeater = makePeerHeartbeater( peer );

// stop them later
// heartbeater.stop();

function makePeerHeartbeater ( peer ) {
    var timeoutId = 0;
    function heartbeat () {
        timeoutId = setTimeout( heartbeat, 20000 );
        if ( peer.socket._wsOpen() ) {
            peer.socket.send( {type:'HEARTBEAT'} );
        }
    }
    // Start 
    heartbeat();
    // return
    return {
        start : function () {
            if ( timeoutId === 0 ) { heartbeat(); }
        },
        stop : function () {
            clearTimeout( timeoutId );
            timeoutId = 0;
        }
    };
}


Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:10
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
afrokickcommented, Mar 28, 2019
1reaction
rc1commented, Jul 30, 2014

It works – at least with Heroku. The server need not do anything. As it stands the server should be parsing the message and printing “Message unrecognised” . But this would be an easy fix if a feature like this were adopted.

I’m not sure that a ping with a pong at JS level would be required to keep a connection alive. Perhaps there is by-directional communication happen at a lower level anyway; just a guess. For the server detecting closed peers, I would have thought WS’s ‘close’ event would be fired and then the clean up happens? If not, perhaps the issue is with WS? Alternatively the server could periodically send a heartbeat back (not in sync with the other heartbeat) and catch the failed write callback.

You are right about the trickiness testing. I wish I had a better way than trail and error. In this case that’s what I’ve done. However here is Heroku’s docs on connection timeouts and this being an acceptable practise.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure Heartbeat monitors - Elastic
You can configure Heartbeat to use the following monitor types: icmp: Uses an ICMP (v4 and v6) Echo Request to ping the configured...
Read more >
Heart health notifications on your Apple Watch
You can enable notifications from the Heart Rate app on your Apple Watch to alert you to high or low heart rates and...
Read more >
2.28. Configuring the Heartbeat Service
Oracle VM VirtualBox ships a simple heartbeat service. Once the Guest Additions are active, the guest sends frequent heartbeat pings to the host....
Read more >
Customizing the heartbeat message - 11.2 - Documentation
The heartbeat endpoint, /pf/heartbeat.ping , returns a customizable OK browser message and an HTTP 200 status indication if the PingFederate ...
Read more >
Heart arrhythmia - Diagnosis and treatment - Mayo Clinic
Tests may be done to confirm an irregular heartbeat and look for conditions that can ... its possible causes and the best treatment...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found