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

Race condition prevents keepalives from working as intended #6

Open
krozett opened this issue May 16, 2016 · 0 comments
Open

Race condition prevents keepalives from working as intended #6

krozett opened this issue May 16, 2016 · 0 comments

Comments

@krozett
Copy link

krozett commented May 16, 2016

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.

krozett added a commit to krozett/ohmage.js that referenced this issue May 18, 2016
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

No branches or pull requests

1 participant