Tovacinni/fix averager memory leak#131
Open
tovacinni wants to merge 3 commits into
Open
Conversation
The executor's three TimeSeriesAverager instances (num_distinct_queues, refresh_queue_duration, dequeue_duration) were appending a DataPoint on every executor poll iteration and never pruning. Because run_round_robin_loop has no sleep when the queue is empty, an idle worker busy-polls the database hundreds of times per second, and each of those iterations submits to 2-3 averagers. On a quiet dev Postgres this leaked roughly 40 MB/min per worker, which at -p 8 produced ~320 MB/min of RSS growth and eventually OOM-killed unrelated processes on the host (dbus, wireplumber, etc.), which in turn took down NetworkManager as collateral damage. Swap data_points for a bounded collections.deque with maxlen=10_000 so append is O(1), old points are auto-evicted, and worst-case memory is capped at ~2 MB per averager regardless of poll rate. clear() and prune_data_older_than() are updated to preserve the deque's maxlen. At ~100 submits/sec the buffer still holds a couple of minutes of stats, which is enough for the existing get_time_series() consumers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The WorkerRootProcess message-listener thread was started without daemon=True, and its body blocks indefinitely on a multiprocessing Queue.get(). The shutdown path tries to wake it with a put(None) sentinel, but after executor processes are SIGKILL'd their queue feeder threads can die mid-send and leave the parent receiver wedged. When join(timeout=5.0) returns with the thread still alive, the code emits a warning and continues — but Python won't exit the interpreter while a non-daemon thread is alive, so the worker process hangs forever after a Ctrl+C / SIGTERM. Mark the listener thread as a daemon at creation time so the interpreter can reap it on exit regardless of queue state. Also update the misleading comment in stop() that referred to promoting the thread to a daemon during shutdown — that's impossible once the thread has started (Thread.daemon setter raises RuntimeError). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.