Fix resource leak and improved wait_for_ready
#2675
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.
I noticed that reloading the frontend would sometimes cause the host server to not respond anymore even though the worker was fine. The cause of this issue was a resource leak with our
_session
client session. Turns out, everything anaiohttp.ClientSession
returns is a resource that must be disposed of. We were not doing that in a few methods, andaiohttp
doesn't do auto-clean up apparently, so after a few leaks the entire backend host server would become unresponsive as_session
would always timeout.Leaks were hard to reproduce btw. I had to do 5 leaky requests to the worker's
/nodes
in parallel for to consistently trigger the bug.The fix was to properly manage resource everywhere. I also improved
wait_for_ready
to not spam the worker with requests by (1) remembering whether we successfully connected to it before and (2) making processing concurrent calls towait_for_ready
sequentially which benefits from (1).