fix(tui): join slash worker drain threads - #53499
Conversation
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Fixes resource leak in _SlashWorker.close() by joining drain threads and closing stdin/stdout/stderr. Clean fix with a dedicated test that verifies thread joining and stream closing.
Reviewed by Hermes Agent
teknium1
left a comment
There was a problem hiding this comment.
Thanks for targeting the remaining slash-worker cleanup gap. The premise is still valid on current main: tui_gateway/server.py:326-327 starts anonymous drain threads and close() ends after stream cleanup at tui_gateway/server.py:391-396, without joining them.
Problems
- The added join loop unconditionally reads
self._stdout_threadandself._stderr_thread. Currenttests/test_tui_gateway_server.py:8252-8255constructs_SlashWorkerviaobject.__new__with onlyproc, so this change raisesAttributeError. The canonical duplicate #53308 recorded and fixed this exact compatibility case inda52fdffb80923bf85efaf94d483584eb427322cusinggetattr(..., None)guards.
Suggested changes
- Use guarded thread lookup and join only present thread objects, then preserve both the existing zombie/FD test and the new drain-join test.
Automated hermes-sweeper review.
| stream.close() | ||
| except Exception: | ||
| pass | ||
| for thread in (self._stdout_thread, self._stderr_thread): |
There was a problem hiding this comment.
This unconditionally reads attributes that are absent on the existing object.__new__(server._SlashWorker) fixture in tests/test_tui_gateway_server.py:8252. Use getattr(self, "_stdout_thread", None) / getattr(self, "_stderr_thread", None) and skip None values so close() remains compatible with that regression path.
Summary
_SlashWorker.close()plus the existing session create/close race guardTesting
Notes
tests/test_tui_gateway_server.py::test_browser_manage_connect_default_local_reports_launch_hintis already failing on an untouched browser-manage path and was treated as unrelated baseline noise for this narrow change.