Skip to content

Conversation

billiegoose
Copy link
Member

@billiegoose billiegoose commented Mar 4, 2020

Currently the Mutex is relying on setInterval(keepAlive, 5000) to refresh it's lease on the mutex. However, this is fatally flawed: there is no guarantee cb will run every 5 seconds. It may not even ever run at all!

In production, we're encountering a scenario where synchronous Markdown parser is running for ~90 seconds. Since JavaScript is single threaded, that means the Mutex is not renewed in time, and other threads decide our thread has crashed, so they go ahead and take the Mutex. Then 85 seconds later, our code continues on, thinking it still has the mutex, then it releases it, only to discover either a) it has lost ownership or b) it is double-freed (because it lost ownership but then the other thread finished its stuff and released the mutex, so nobody has it now).

The only reliable way to fix this is to always double check that our mutex lock hasn't expired before we do things that require the lock. If it has expired, we try to renew our lock. If that fails we throw an ETIMEOUT.

@billiegoose
Copy link
Member Author

Freaking Safari again.

Screw it. Major version bump.

@billiegoose billiegoose merged commit ac65928 into master Mar 5, 2020
@billiegoose billiegoose deleted the fix/mutex-wip branch March 5, 2020 00:27
@billiegoose billiegoose changed the title fix: eliminate Mutex's reliance on setInterval (WIP) fix: eliminate Mutex's reliance on setInterval Mar 5, 2020
@isomorphic-git-bot
Copy link
Member

🎉 This PR is included in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants