| Type |
Bug
|
| Priority |
Normal
|
| Assignee | |
| Affected Versions |
17.2.6
|
| Labels |
No labels
|
Issue Votes (0)
| Type |
Bug
|
| Priority |
Normal
|
| Assignee | |
| Affected Versions |
17.2.6
|
| Labels |
No labels
|
The job housekeeping loop can interrupt a newly starting Docker job even though the server still considers the build active. The loop snapshots jobThreads, checks that snapshot against the server, then iterates the live jobThreads map and cancels everything absent from the earlier snapshot. Jobs registered while the checks are in progress can therefore be cancelled without ever having been checked.
This is a source-level race report. Existing production logs are consistent with it, but do not record the originating housekeeping decision, so they do not conclusively establish that this race caused each observed interruption.
Versions and source Observed server version: OneDev 17.2.6, which selects agent 4.1.8 and commons 4.3.1 (https://github.com/theonedev/onedev/blob/v17.2.6/pom.xml#L720-L722). The runtime stack line numbers match this agent source:
Snapshot, server checks and live-map cancellation: https://github.com/theonedev/agent/blob/561f76c65e51332e5cc257a7ffdcf0a599d861cd/src/main/java/io/onedev/agent/AgentSocket.java#L1494-L1505 Cancellation removes a job and interrupts its worker thread: https://github.com/theonedev/agent/blob/561f76c65e51332e5cc257a7ffdcf0a599d861cd/src/main/java/io/onedev/agent/AgentSocket.java#L577-L581 Job registration before Docker initialization: https://github.com/theonedev/agent/blob/561f76c65e51332e5cc257a7ffdcf0a599d861cd/src/main/java/io/onedev/agent/AgentSocket.java#L809 Housekeeping loop and five-second delay: https://github.com/theonedev/agent/blob/561f76c65e51332e5cc257a7ffdcf0a599d861cd/src/main/java/io/onedev/agent/Agent.java#L361-L364 Interleaving
Housekeeper copies currently registered jobs into its local runningJobs map. Housekeeper begins the HTTP status checks for the copied jobs. Another worker registers a new job in jobThreads and starts initialization. The new job is absent from runningJobs, because it was not present when that snapshot was collected. Housekeeper iterates the current jobThreads.keySet() and invokes cancelJob for the new token. The new job's worker thread is interrupted without a negative status response for that token. The race also exists when the snapshot is initially empty.
Symptoms Several unrelated Docker jobs on the same agent failed during JobUtils.createNetwork or AgentUtils.getId, before any configured build step started. The deepest cause was InterruptedException in ProcessImpl.waitFor through Commandline.execute. In two recent cases the agent logged the interruption 52 ms and 271 ms after the recorded job start. The server later marked the builds FAILED with no recorded canceller. No newer build of the same job/ref was submitted until after the failed build ended, which rules out ordinary build supersession in those cases.
Expected behavior Housekeeping should only cancel a job that was included in its status-check snapshot and received an explicit negative server response. A job that appears after snapshot collection should remain untouched until a later housekeeping pass checks it.
Suggested fix Snapshot the token together with its RunningJob registration object and iterate only that snapshot. For a checked token that receives an explicit false response, cancel only if the current registration is still the identical one. Keep the existing conservative behavior on failed or indeterminate status requests. Please also make sure cancellation and job completion cannot race, so that a delayed Thread.interrupt() cannot hit an unrelated task after a pooled thread has been reused.
Suggested regression tests
Pause housekeeping right after the snapshot, register a new job, then resume; the new job must not be checked or cancelled in that pass. Repeat with an empty snapshot and with two concurrent new registrations. A snapshotted job with a definitive false status is still cancelled exactly once. A failed status GET is not treated as a definitive false response.