Link shutdown routine and sigterm handler to main thread #5555
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently when a SIGTERM signal is received by worker or workflow engine, sigterm handler runs in a new thread. Sigterm handler throws SystemExit exception which should be caught in the main thread for shutdown routine to be executed.
(https://github.com/StackStorm/st2/blob/master/st2actions/st2actions/cmd/actionrunner.py#L74 https://github.com/StackStorm/st2/blob/master/st2actions/st2actions/cmd/workflow_engine.py#L75)
However the above expected behaviour doesn't happen always. When we have other green threads processing messages SystemExit exception can be caught by these thread. And if the try-except block doesn't re-raise the exception, the shutdown routine is never executed.
This PR will take care of raising the exception in main thread, so that it can be caught and shutdown routine can complete properly. Ref https://eventlet.net/doc/modules/greenthread.html#eventlet.greenthread.GreenThread.kill
Issues seen locally when multiple executions are being processed.