agenda icon indicating copy to clipboard operation
agenda copied to clipboard

fix: _unlockJobs should return when it resolves

Open esclapes opened this issue 2 years ago • 2 comments

Calling resolve does not stop the function execution. This can lead to the updateMany call happening even though the promise has resolved and the promise is no longer awaiting.

For instance in this code:

await agenda.stop()
await agenda.close()

We may find that we already closed the connection when the stop code is still trying to reach the Mongo DB

esclapes avatar Oct 12 '21 13:10 esclapes

Thanks for the review @pdfowler

Only nit would be to call return after calling resolve

I was curious about this one and it turns out it does not make a difference. According to the Promise costructor docs:

The executor return value is ignored.

Thus, the promise will resolve to undefined because resolve() is called without passing any value.

Maybe a less confusing approach would be to complete the if statement with an else branch so that we don't really need to ~resolve~ return at all. Happy to go either way.

esclapes avatar Oct 22 '21 08:10 esclapes

The more you know™ ... thanks for the reference. I think the else approach would be overkill and this can be merged as-is.

Now to see if this will help stabilize some intermittent issues in my test suite 🤔

pdfowler avatar Dec 01 '21 03:12 pdfowler