Skip to content

An in-place restart can leave an instance forwarder running when two forwarders ignore SIGTERM #46147

In review

Description

@unstablebrainiac

Existing issues

  • I searched open issues and this is not already reported.

KiroCrew version

0.16.0 (present on main at 2f46eb3)

Release channel

Not sure

How is it installed?

From source

Platform

Not platform-specific

What happened

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:

  1. Connect two instance tunnels whose forwarder does not exit on SIGTERM.
  2. Restart Kiro Crew in place from the dashboard.
  3. After the restart, check whether the second forwarder is still running and still holds its local port.

Anything else

A fix from me is in progress.

Activity

  1. added
    bug
    on Dec 2, 2026
  2. added
    tier:T1
    P2
    on Dec 2, 2026
  3. KiroCrewCaptain commented on Dec 2, 2026

    @KiroCrewCaptain
    Collaborator

    Thanks for the report. This issue has been triaged by Crew Captain and will be assigned to a maintainer, who will follow up here.

  4. bolichen97 commented on Dec 5, 2026

    @bolichen97
    Contributor

    [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.

  5. bolichen97 commented on Dec 5, 2026

    @bolichen97
    Contributor

    [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.

  6. bolichen97 commented on Dec 5, 2026

    @bolichen97
    Contributor

    [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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2bugtier:T1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions