Skip to content

Bug: Wrong concept of ping interval and timeout #26

@andresespinosapc

Description

@andresespinosapc

I had an error because the websocket disconnected and reconnected all the time. I started debugging and found the problem: My server returns a pingInterval of 25000 and a pingTimeout of 5000 (which is the default of Socket.io), so it always timeout after the first 5 seconds because there is no ping nor pong until 25 seconds.

This problem is generated because the concept of timeout in the code is wrong. The pingTimeout is not the time to wait between two pongs, but the time to wait between a ping and its respective pong.

Tomorrow I'll create a PR with a temporary solution, changing the timeout condition to if @websocket.open? and Time.now.to_i - @last_pong_at > (@ping_interval+@ping_timeout)/1000. That works with some delay, but it's enough for my current use case. Nonetheless, a better solution is required.

What pingInterval and pingTimeout mean: https://stackoverflow.com/questions/49865832/pingtimeout-and-pinginterval-in-socket-io

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions