Unreference timer created in parseWorkflowCode #1370
Merged
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.
What was changed
Unreference timer created in
parseWorkflowCode
which can prevent Node.js from closing the event loop until the timer has fired.Why?
The
parseWorkflowCode
function creates a 10 second timeout to keep the script and context from getting garbage collected. For normal usage that timeout is not a problem, since workers are expected to run for longer than 10 seconds anyway.However, when running unit tests these timers can keep the Node.js event loop from shutting down even after the tests have completed successfully, if the tests complete in less than 10 seconds. That's especially common when running individual tests cases rather than the entire test suite.
The fix is rather simple. We just need to "unreference" the timer, to prevent it from keeping the event loop alive unnecessarily.
Running a single "replay history" workflow test without this fix:
Rerunning the same test case with the fix:
Overall, execution time of the test running has decreased from 16s to 13s by not waiting for the 10s timeout. (There is some other cleanup work that's happening as well, which is preventing the test suite from shutting down even faster after the test has completed. But evern second in lost developer productivity counts. 😄)
Checklist
Closes: none. Didn't file an issue for this because it doesn't affect normal usage of the worker and the fix is trivial.
How was this tested: Tested this locally while executing our own test suite. (See above.)
Any docs updates needed? No.