You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An in-place restart can leave an instance forwarder running when two forwarders ignore SIGTERM #46147
I found this while reading the restart's pre-exec stops. I have not reproduced it yet: it is reasoned from the code on main at 2f46eb3.
Before an in-place restart execs, Kiro Crew runs its pre-exec stops together and abandons them after 10 s (pre_exec_stops.PRE_EXEC_STOP_TIMEOUT_SECS). The comment on that constant sizes the limit for one wedged child plus the rest. The "Instance tunnels" stop (SshTunnelManager.shutdown) stops its tunnels one after another, and each _SshTunnel._terminate() sends SIGTERM, waits up to 5 s (_TERMINATE_WAIT_SECS), and only then sends SIGKILL.
So with two forwarders that do not exit on SIGTERM (the _terminate() docstring names a session-manager-plugin that does not finish on SIGTERM), the second one gets its SIGTERM about 5 s in, and its SIGKILL would come a little after 10 s in. The restart's limit cuts the stop at 10 s first. That cancellation lands in the second forwarder's wait, which catches only asyncio.TimeoutError and ProcessLookupError, so no SIGKILL is sent, and the forwarder keeps running after the restart with its local port still bound.
I expect every instance forwarder to be killed before the restart's limit, however many of them hang.
Steps to reproduce
I have not run these yet:
Connect two instance tunnels whose forwarder does not exit on SIGTERM.
Restart Kiro Crew in place from the dashboard.
After the restart, check whether the second forwarder is still running and still holds its local port.
[operator: bolichen97] Picking this up since it has been quiet for a while; @tim-finnigan@unstablebrainiac shout here if you are still on it.
Plan: make sure an in-place restart ends every instance forwarder before it execs, however many of them ignore SIGTERM. I will reproduce it on a Linux test machine first (forwarders that ignore SIGTERM, then the restart's pre-exec stops) and post the result here.
[operator: bolichen97] Reproduced on a Linux test machine (Ubuntu 24.04, x86_64, Python 3.12), on main at 0d85f41.
How: real SshTunnelManager tunnels whose forwarder is a local stand-in for ssh that ignores SIGTERM, then the restart's own run_pre_exec_stops() with the production 10 s bound and 5 s wait.
2 forwarders that ignore SIGTERM: the stop run was cut at 10.0 s ("Instance tunnels stop before restart did not finish in 10s; restarting anyway"); the second forwarder was still running afterwards and still held its local port.
3 such forwarders: the second and third were still running and held their ports.
2 forwarders that exit on SIGTERM: all gone, 0.0 s.
The same through two real gateways (a hub with two connected instances, then POST /api/restart on the hub): after the restart one of the two old forwarders was still running and holding its port, and the hub logged the same "did not finish in 10s" warning.
Fix coming in a PR: stop all the tunnels at once, so each SIGTERM-deaf forwarder's 5 s wait runs beside the others' and every one is killed inside the bound.
[operator: bolichen97] Fix is up for review: #47884. SshTunnelManager.shutdown() now stops every tunnel at once, so each forwarder that ignores SIGTERM is killed about 5 s into the restart's teardown, inside the 10 s bound. On the same Linux test machine, with the fix: no forwarder or port is left after the restart's pre-exec stops (2 or 3 SIGTERM-deaf forwarders, finished in 5.0 s), and none is left through a real gateway's POST /api/restart. The new test fails on main and passes on the fix.
Activity
KiroCrewCaptain commentedon Dec 2, 2026
Thanks for the report. This issue has been triaged by Crew Captain and will be assigned to a maintainer, who will follow up here.
bolichen97 commentedon Dec 5, 2026
[operator: bolichen97] Picking this up since it has been quiet for a while; @tim-finnigan @unstablebrainiac shout here if you are still on it.
Plan: make sure an in-place restart ends every instance forwarder before it execs, however many of them ignore SIGTERM. I will reproduce it on a Linux test machine first (forwarders that ignore SIGTERM, then the restart's pre-exec stops) and post the result here.
bolichen97 commentedon Dec 5, 2026
[operator: bolichen97] Reproduced on a Linux test machine (Ubuntu 24.04, x86_64, Python 3.12), on main at 0d85f41.
How: real
SshTunnelManagertunnels whose forwarder is a local stand-in forsshthat ignores SIGTERM, then the restart's ownrun_pre_exec_stops()with the production 10 s bound and 5 s wait.The same through two real gateways (a hub with two connected instances, then
POST /api/restarton the hub): after the restart one of the two old forwarders was still running and holding its port, and the hub logged the same "did not finish in 10s" warning.Fix coming in a PR: stop all the tunnels at once, so each SIGTERM-deaf forwarder's 5 s wait runs beside the others' and every one is killed inside the bound.
bolichen97 commentedon Dec 5, 2026
[operator: bolichen97] Fix is up for review: #47884.
SshTunnelManager.shutdown()now stops every tunnel at once, so each forwarder that ignores SIGTERM is killed about 5 s into the restart's teardown, inside the 10 s bound. On the same Linux test machine, with the fix: no forwarder or port is left after the restart's pre-exec stops (2 or 3 SIGTERM-deaf forwarders, finished in 5.0 s), and none is left through a real gateway'sPOST /api/restart. The new test fails on main and passes on the fix.