Skip to content

Race condition prevents keepalives from working as intended #6

@krozett

Description

@krozett

I run oh.keepalive() but it only runs the ping once and stops working after that. I did some investigation (using lots of console logs!) and learned some things about our implementation. oh.ping relies on debounce, copied from underscore.js. All the functions behave as intended. However:

  • If the debounced function is set to a wait of N seconds, and N or more seconds have elapsed, running it works as normal. The wait timer is reset.
  • If N seconds have not elapsed, the function does not run. This is key: the wait timer is reset in this case too.

You can test this by calling oh.ping() every 50 seconds. It will never actually make the whoami request, because its internal counter is reset every time, and can only run once every minute. By default, oh.keepalive tries to run every 60 seconds, but due to a race condition, it thinks the timer hasn't elapsed yet, and then resets it. If you set the keepalive interval to something like 65 seconds, it works just fine.

oh.keepactive also does not work correctly. If the user clicks more than once a minute, no pings will be sent to the server.

I think the issue is that we are using debounce as a throttling function, which is not its intended purpose. Underscore.js has a throttle function (http://underscorejs.org/#throttle) which we should use instead.

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