Repository navigation
[Fix] Stop the web app's whole process group on cleanup - #89
Open
aaronsmulktis wants to merge 4 commits into
Open
aaronsmulktis wants to merge 4 commits into
aaronsmulktis wants to merge 4 commits into
Conversation
The web app runs as bash -c "... && uv run launch.py" in its own session, and cleanup() called terminate() on the bash wrapper only. bash exited; uv and the server were reparented to init and kept serving, so every launch_agent run left a server holding a port. Signal the process group instead (SIGTERM, then SIGKILL), waiting on the group rather than on bash. Also stop the app when the server never comes up or on Ctrl-C, which escaped except Exception.
This branch has not been deployed
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.
Why this PR?
Every
launch_agent.pyrun left its OpenApps web server running after it exited. After a day of local runs I had nine orphaned servers holding ports 5001–5901, each parented tolaunchd.The web app is started as
bash -c "source … && cd … && uv run launch.py …"withstart_new_session=True.cleanup()calledapps_process.terminate(), which signals only that bash wrapper. bash exits, anduvand the server under it are reparented to init and keep serving.The leaked servers pile up. In a
conduct.shpool they collect across runs for the life of the allocation, and every port they hold pushes later runs further along their search. That port pressure is how #88's collisions showed up.What changes
stop_process_group()inlauncher.pysends SIGTERM to the whole process group, then SIGKILL after a timeout. It waits on the group, not on bash, because bash can exit long before the server does. It reaps the wrapper as it goes, since an unreaped zombie still counts as a group member. This matches howtests/save_screenshots.pyalready stops its server.AgentLauncher.launch()now stops the app in afinally. Two exits used to skip cleanup entirely: a server that never came up (wait_until_apps_startraising), and Ctrl-C (KeyboardInterruptslipped pastexcept Exception).kill_portsfallback after a timeout is gone. Killing the group covers it, and killing by port number could hit another run's server on a reused port.Test plan
tests/test_launcher_cleanup.py:bash -c "… && child"wrapper is gone after cleanup;terminate()against the same setup leaves the child running, so the first test catches the regression.test_launcher_recording.pyandtest_parallel_tasks.py: 27 passed.uv run launch_agent.py agent=dummy task_name=add_meeting_with_dennisends with "OpenApps successfully stopped". Afterwards nothing OpenApps is listening and nolaunch.pyprocess remains.signalis now used.