Skip to content

JobCancelMessage carrying the request id is silently dropped; the miss is logged only at Verbose #4783

Open

Description

@grad-code-agent

Describe the bug

On self-hosted broker-flow runners, a JobCancelMessage whose JobId equals the runner request id acknowledged for the job is silently ignored. JobDispatcher.Cancel looks the value up in _jobInfos, which is keyed by job id, misses, and logs the miss only at Verbose. At Info, the only trace is the "Job cancellation request ... received" line. The job keeps running until it finishes on its own or until the next job dispatched to that runner releases it.

In our logs about 10% of jobs have an acknowledged request id that differs from the job id. Cancels that carry the job id are forwarded to the worker; cancels that carry the request id were all dropped in our sample (roughly 0.3% of all jobs had a cancel dropped this way).

To Reproduce

Hard to reproduce on demand, since it needs the service to send a request-id cancel. Observed in production logs:

  1. Run a self-hosted runner (v2.337.0 or v2.338.0) with the broker message flow on macOS.
  2. Dispatch a job acknowledged with request id <request-id-X> while its job id is <job-id-Y>.
  3. Cancel the workflow run, then observe the log below.

Default (Info) log, placeholders for identifiers, relative timestamps:

T+00:00  Acknowledging runner request '<request-id-X>'
T+00:01  Job request 0 for plan <plan-id-P> job <job-id-Y> received.
T+00:01  Send job request message to worker for job <job-id-Y>.
T+01:00  Job cancellation request <request-id-X> received, cancellation timeout 5 minutes.
T+01:01  Job cancellation request <request-id-X> received, cancellation timeout 5 minutes.
T+01:01  Job cancellation request <request-id-X> received, cancellation timeout 5 minutes.
         (no "Send job cancellation message to worker for job <job-id-Y>" line)
T+0x:xx  finish job request for job <job-id-Y> with result: <result>

Expected behavior

Either the cancel is matched to the running job, or the failed match is logged at Info or Warning so operators can see that the cancel was not applied. Today the miss is logged only at Verbose.

Runner Version and Platform

  • Runner: v2.337.0 (same cancel path in v2.338.0); OS: macOS; self-hosted, broker message flow

What's not working?

Cancels that carry the request id are dropped, and nothing at default log level says so.

Analysis from source (tag v2.338.0; v2.337.0 has the same cancel path)

  • The job is acknowledged with the request id: Runner.cs L697 calls AcknowledgeMessageAsync(messageRef.RunnerRequestId, ...), which logs Acknowledging runner request at Info (BrokerMessageListener.cs L437).
  • The job body is fetched with the same id (Runner.cs L722, L735). JobDispatcher.cs L91 logs Job request {RequestId} ... job {JobId} received; in our broker-flow logs {RequestId} prints as 0.
  • Active workers are stored in _jobInfos, keyed by job id (JobDispatcher.cs L53); entries are added at L136.
  • A JobCancelMessage is deserialised and passed to jobDispatcher.Cancel (Runner.cs L774-L775).
  • JobDispatcher.Cancel, L140-L159 logs the request at Info (L142), then looks up _jobInfos[JobId] (L145). On a miss it logs at Verbose (L147) and returns without forwarding. Only a hit reaches workerDispatcher.Cancel (L152).
  • The worker kill timer (the cancellation timeout minus 15 s) is armed only in WorkerDispatcher.Cancel (L1285), which a miss never reaches.
  • The default trace level is Info (TraceSetting.cs L13); Verbose needs a DEBUG build (L15) or GITHUB_ACTIONS_RUNNER_TRACE (L17-L21).
  • Runner.cs L776 deletes the cancel message unless an auto-update or run-once condition holds and the cancel was not applied, so a dropped cancel is not redelivered.

Impact

  • The job keeps its runner slot until it finishes. In dropped cases released by a later dispatch, the next job arrived 14-25 s before the old job finished, and the old job ran 245-319 s after the cancel. Other dropped cases ran to completion.
  • In our sample, GitHub recorded every run and job with a dropped cancel as cancelled. The runner's local result was Canceled or Abandoned in most cases and Succeeded in the rest, where the job kept running to completion.

Suggested fix

  • Resolve a cancel by job id or acknowledged request id (for example, map request id to job id at dispatch), and forward either form.
  • Log a miss in JobDispatcher.Cancel at Info or Warning, with the cancel id.

Workaround

Stopgap: alert on a request-id cancel with no matching Send job cancellation message to worker line for that job.

Frequency

  • About 10% of jobs have differing request and job ids.
  • Request-id cancels: all dropped in the sample (100%), about 0.3% of all jobs. Job-id cancels: about 99.8% forwarded.
  • Sample: several hundred cancels over about two weeks.

Related issues

No open or closed issue describes the request-id versus job-id mismatch in JobDispatcher.Cancel. Related but different: #4569 (redelivery loop), #4670, #4357, #4668.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions