node-persistent-queue icon indicating copy to clipboard operation
node-persistent-queue copied to clipboard

SIGSEGV when queue is stopped and closed before task is finished

Open mass85 opened this issue 7 years ago • 3 comments

In a following scenario crash will occur:

  1. Open and start queue
  2. Add new task, let it start
  3. Stop and close queue before task completes
  4. Make sure task completes and queue.done() is called

This will schedule removal of task from database, but database is already closed. There is a workaround - in task executor (on('next)) do not call done() when queue is not running. However that workaround should be rather part of the queue implementation.

mass85 avatar Oct 30 '18 13:10 mass85

hi @mass85

Just trying to get a sense of your use case.

At point 3:

Stop and close queue before task completes

Do you want to terminate the script, but wait until the currently running task completes?

If so, perhaps Queue could emit a 'done' event each time the done() method is called, so that you can know a task has completed. Then when you want to terminate, stop the queue, and assign a listener to the 'done' event that closes the database.

If I haven't understood your usage case correctly, perhaps you could elaborate?

D.

damoclark avatar Nov 01 '18 02:11 damoclark

The described problem appeared in tests. Each scenario creates a new object that contains the persistent queue, queue is started at the beginning of scenario and stopped at the end. The executed task did a REST API call, which succeeded, test noticed that and passed - in the clean up phase queue was stopped and closed, but the callback for REST call was not called yet, so the queue.done() was not called as well.

To abstract from this use case and make it more general - when client stops and closes the queue, it means he no longer cares about current task in progress, so that its result can be ignored. You could go even one step further and cancel current task, but I rather do not need that.

mass85 avatar Nov 02 '18 10:11 mass85

I understand your usage case. I think I'll look at both:

  1. queue.done() checking if the db is closed and if so, not updating the queue
  2. queue emitting a done event so that the queue can be stopped, closed and the script can terminate before commencing another task.

I'll come back to this soon.

D.

damoclark avatar Nov 07 '18 11:11 damoclark