Engine: encourage better garbage collection #932
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 c
2E19
hange 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.
Short Description
This PR fixes an issue in the engine where state references are not garbage collected, and so memory leaks over time.
This is a probably cause of at least some lost runs.
Fixes #826
Implementation Details
After a heck of a lot of investigation I've worked out that the suspect memory leak flagged by @taylordowns2000 is real. I've also worked out that it comes from the engine, and if you cut out child processes and the runtime and just statically return a large object from each run, the leak still occurs
What seems to be happening is:
The fix - the dumbest, easiest fix I can find - is to force that object to be unreferenced after the workflow has finished.
I've added a new
test:mem
script to the engine. This creates an engine with quite a low memory limit, and then infinitely runs a job with a large-ish payload.Against
main
the test fails (heap error) on my machine after about 20 runs.At the time of writing, on this branch, I've just crossed
2000300040005000 runs (my poor CPU!)AI Usage
Please disclose how you've used AI in this work (it's cool, we just want to know!):
You can read more details in our Responsible AI Policy