Skip to content

A waiting held lease can't be cancelled: SIGINT is ignored until grant, a killed CLI's request stays queued, and the CLI has no cancel #1249

Closed

Description

@andthezhang

What happened

simlock 0.5.0, one gateway and one worker. A held simlock lease --platform ios --bind-pid <pid> --timeout 30m (run on the gateway's machine, so it goes through the gateway) was waiting in the queue. Then:

  1. SIGINT to the CLI while it waits: the process stays alive and the request stays queued. cli/commands/lease.js races termination.settled only after client.requestLease() resolves, so a signal or a dead --bind-pid process during the wait is noticed only at grant time, when the device is released at once.
  2. SIGTERM / kill of the CLI while it waits: the CLI exits, but the gateway keeps the request queued (seen in simlock status as a waiter for minutes). When it is reached, device work starts for a requester that is gone (DELETE /v1/lease-requests/<id> then answers 409 REQUEST_NOT_CANCELLABLE), and the grant is never released before its TTL.
  3. The CLI has no way to cancel a waiting request: simlock release takes only a lease id (UNKNOWN_LEASE for a request id), and simlock release --all run as admin releases every requester's leases, not only the caller's.

What I expected

  • A held simlock lease that gets SIGINT/SIGTERM, or whose --bind-pid process exits, while it waits cancels its request (as the programmatic client's abort does) and exits.
  • A request whose client connection is gone leaves the queue (or the gateway cancels it when the socket closes).
  • A CLI way to cancel: simlock lease cancel [--platform ios] for the calling requester, matching the daemon's lease.cancel.
  • simlock release --all limited to the calling requester unless --any-requester is given; it surprised us as admin.

Why it matters

A test runner that is stopped while waiting for a simulator either keeps its place in the queue, or later takes a device nobody will release, and it blocks everyone behind it on a worker with two slots.

Activity

  1. added
    bug:new
    on Nov 5, 2026
  2. self-assigned this
    on Nov 5, 2026
  3. V3RON commented on Nov 5, 2026

    @V3RON
    Contributor

    Reproduction

    Defect, confirmed for SIGINT, SIGTERM and --bind-pid exit. Test on bug/1249-repro: src/cli/index.test.ts, "cancels its waiting request and exits 0 on $trigger before a grant".

    pnpm exec vitest run --project unit src/cli/index.test.ts -t "cancels its waiting request"
    
    × cancels its waiting request and exits 0 on SIGINT before a grant
    × cancels its waiting request and exits 0 on SIGTERM before a grant
    × cancels its waiting request and exits 0 on the exit of the --bind-pid process before a grant
    AssertionError: expected undefined to be true
     ❯ expect(requestSignal?.aborted).toBe(true);
    

    Corrections: the CLI catches SIGTERM the same way it catches SIGINT, so a CLI that exited while waiting was SIGKILLed. A killed CLI's request staying queued is ADR 0004 §3 ("connection close means nothing to a lease", src/daemon/server.ts:1388); changing that needs a superseding ADR. simlock lease cancel and a narrower release --all (documented as "every lease") are feature requests.

    Root cause

    src/cli/commands/lease.ts:93-95 sets up the signal and --bind-pid handlers before the request, which turns off Node's default exit. But client.requestLease (lease.ts:182) gets no signal, and termination.settled is awaited only at lease.ts:231, after the grant. So while the request waits, the signal is caught and does nothing. The client already cancels a request when its signal aborts (src/simlock-client/client.ts:863: lease.cancel, then it releases a grant that lands anyway).

    Simplest fix

    In runLease, abort an AbortController when termination.settled resolves. Pass its signal to requestLease. Return 0 when the request rejects with CANCELLED after that abort. Exit 0 is the shape the test pins (like "0 after it released the lease on request"). I tried this locally: all 414 tests in the file pass.

    Alternatives rejected

    • Cancel when the daemon socket closes: goes against ADR 0004 §3.
    • Exit 1 (CANCELLED's code): a stop the caller asked for is not a failure.

    Risk

    • --detach has no termination watch and must still send no signal.
    • A grant that lands during the cancel must be released and not printed to stdout.
    • cli.mdx should say a signal also cancels a waiting request.

    Written by an agent.

  4. removed their assignment
    on Nov 5, 2026
  5. added
    bug:ready
    and removed
    bug:new
    on Nov 5, 2026
  6. self-assigned this
    on Nov 5, 2026
  7. V3RON commented on Nov 5, 2026

    @V3RON
    Contributor

    Scope

    • A held simlock lease that gets SIGINT or SIGTERM, or whose --bind-pid (or parent) process exits, while its request waits cancels that request and exits 0, as the triage report's simplest fix says. The failing test on bug/1249-repro is the regression test. (decided in delivery, pending the maintainer)
    • Out of scope: a simlock lease cancel command, limiting release --all to the caller, and the gateway cancelling a request when its connection closes (ADR 0004 §3). (decided in delivery, pending the maintainer)
    • Tests: "cancels its waiting request and exits 0 on $trigger before a grant" (src/cli/index.test.ts), one case each for SIGINT, SIGTERM and the --bind-pid exit.

    Written by an agent.

  8. V3RON commented on Nov 5, 2026

    @V3RON
    Contributor

    Delivery run

    Merged: #1316 (#1249)
    Parked: none
    Waiting: none
    Decided: #1249 — scope of the fix → only the CLI cancels its waiting request on SIGINT, SIGTERM or the --bind-pid/parent exit; lease cancel, release --all scoping and gateway cancel-on-close left out

    Written by an agent.

  9. added a commit that references this issue on Nov 5, 2026
    34edb50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions