Skip to content

simlock lease ignores a SIGTERM in its first second, and the request it then queues outlives the process #1473

Closed

Description

@V3RON

What happens. A SIGTERM that reaches simlock lease during its first second is lost. The command keeps running, and its request is sent and queued anyway. A second SIGTERM then kills the process with exit 143 (no handler), and the request stays queued. When a device frees up, the request is granted to a requester that no longer exists, so the device is held until the lease's TTL. #1316 promises that a signal while the request waits cancels it and exits 0. That does work once the request is queued, and when a --bind-pid process exits.

Where. Likely src/cli/commands/lease.ts:187. The termination watch is armed before connectDaemonClient, and on settle it calls waitAbort.abort() only if ourLeaseId is unset. A signal that arrives before client.requestLease(...) is called aborts a controller the request then gets already aborted, and nothing checks signal.aborted before sending. Not confirmed.

Seen. main at 30f8fad9, macOS arm64. With capacity.strategy=fixed, capacity.config.maxRunning=1 and one iOS lease held by agent a:

simlock lease --platform ios --agent-id b > b.out 2> b.err &
sleep 0.3; kill -TERM $!

15 s later the process is still alive, and simlock list --requests shows b, ios class phone, queued at 1. A second kill -TERM exits 143, and the request is still queued. In another run, the request outlived its process and was granted a lease (lease.granted, no lease.rejected with reason:"cancelled"). The same signal sent after list --requests shows the request as queued exits 0, prints nothing on stdout and cancels it (lease.rejected with reason:"cancelled").

Found during the pre-release e2e pass after v0.6.0.

Written by an agent.

Activity

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

    @V3RON
    ContributorAuthor

    Reproduction

    Defect, confirmed. A signal during the connect is turned into an abort only after the request is on the wire. The window after the send is a second defect, in the client: #1479.

    src/cli/index.test.ts, "sends no lease request and exits 0 on $trigger while it connects" (SIGINT, SIGTERM, --bind-pid exit), on bug/1473-repro:

    pnpm exec vitest run --project unit src/cli/index.test.ts -t "while it connects"
    × ... on SIGINT / SIGTERM / the exit of the --bind-pid process while it connects
    AssertionError: expected 1 to be +0
     ❯ src/cli/index.test.ts:7366:26   expect(sentRequests).toBe(0);
    

    Root cause

    src/cli/commands/lease.ts:187. The termination.settled.then(...) that aborts waitAbort is attached after await connectDaemonClient (line 98), which lazy-loads the admin client. A signal during the connect resolves settled, but the callback runs one microtask after client.requestLease (line 195) has already checked signal.aborted (client.ts:618) and sent the frame. The abort then sends lease.cancel, which the daemon answers not-found because the request is not admitted yet. The client waits on a request that is now queued (#1479). finish (termination.ts:21) has already removed the handlers, so the second SIGTERM kills with 143.

    Simplest fix

    Move let ourLeaseId, waitAbort, cancelledWhileWaiting and the settled.then block (with its why:) above connectDaemonClient. The client then rejects CANCELLED with nothing sent.

    pnpm exec vitest run --project unit src/cli/index.test.ts
    Tests  425 passed (425)
    

    Alternatives rejected

    Risk

    Fast track

    Side findings

    Written by an agent.

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

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1482 (#1473)
    Parked: none
    Waiting: none
    Decided: none
    Asleep: 15 min

    Written by an agent.

  8. added a commit that references this issue on Nov 10, 2026
    b3225c6
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