Skip to content

Switchable server side PONG #2186

@tomarigr

Description

@tomarigr

Is there an existing issue for this?

  • I've searched for any related issues and avoided creating a duplicate issue.

Description

Hello, I know that as per RFC a WS server/client running on this library will automatically pong when a ping is received. While this is great and makes everyone's life easier, sometimes this is not ideal.

A good example is troubleshooting a device/system internet recovery strategy on demand.
As such, I wanted to see what my device will do if a WS ping was not responded and test that my code will try to re-init the LTE modem if it discovers that a certain number of WS pings were not getting a response.

To give some context, it was found that due to some problems the mobile operator randomly is facing, although the connection status remains "connected" and the data channel seems UP, data packets are actually getting lost unless the client disconnects completely from the base station and re-connects.

Although testing this on an ethernet/wifi connected device is easy, just unplug/turn off wifi or the likes, deactivating/re-activating a simcard to simulate network down usually takes time and makes troubleshooting these types of failures a painful time consuming process.

A quick solution was to manually edit the library and add a single if(process.env.BLOCK_PONGS!="on") { on line 1218 of websocket.js and this little hack did the trick for me as I was able to switch auto ponging on an off on demand from my app, or keep it off and handle socket.on('ping' and socket.on ('pong') events and manually .ping() and .pong().

I was thinking that making the automatic pong of this library officially switchable and on by default gives more control to the devs to decide what to do and perhaps chose to manually handle it in the code in some edge cases like mine.

ws version

all

Node.js Version

No response

System

No response

Expected result

No response

Actual result

No response

Attachments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions