node-redlock icon indicating copy to clipboard operation
node-redlock copied to clipboard

Strange behavior with lock()

Open gurupras opened this issue 3 years ago • 1 comments

I suspect this might be related to some of the other issues with the bug label, but adding my 2c just in case it provides some clues.

I have the following code:

const SERVERS_KEY = 'servers'
...
log.debug('[producer:close]: Asking redis to remove producer', { roomName, producerId, routerId })
try {
  const lock = await this.redisLock.lock(SERVERS_KEY, 3000)
  log.debug('[producer:close]: Updating redis', { producerId, routerId })
  ...
  log.debug('[producer:close]: Updated redis', { producerId, routerId })
  lock.unlock()
} catch (e) {
  log.error('Failed to remove producer from redis', { roomName, producerId, routerId }, e)
}
log.debug('[producer:close]: Asked redis to remove producer', { roomName, producerId, routerId })

When running some tests, I sometimes find the Asking redis to remove producer log statement being logged, but nothing else. The node process even terminated without ever receiving the Updating redis ... or the Asked redis to remove producer log messages or even a console.error.

My understanding is that as long as there is something in the event queue, the node process will keep going. How is it that the node process is happily running through the test and terminating with a 0 error code when redisLock.lock() has neither resolved or rejected?

Now, obviously the unexpected behavior may be a result of my code.
However, I wrote a tiny shim for https://github.com/thedeveloper/warlock and found that my code behaves as expected when using that library.

gurupras avatar Mar 23 '21 12:03 gurupras

Hey @gurupras, thanks for the report. What version of redlock is being used here? That's very strange behavior indeed, and I agree that you should see either the error log or the "Asked redis to remove producer" log. Do you happen to call process.exit() anywhere in your code?

mike-marcacci avatar Nov 26 '21 17:11 mike-marcacci