PicoD subprocess execution does not respect incoming HTTP request cancellation
Maintainers usually reply within 1 day
Assessment
This issue has not been assessed yet.
Description
Title
PicoD subprocess execution does not respect incoming HTTP request cancellation
Description
The PicoD execution handler creates the command context using context.Background() rather than the incoming HTTP request context:
ctx, cancel := context.WithTimeout(context.Background(), timeoutDuration)
defer cancel()
cmd := exec.CommandContext(ctx, req.Command[0], req.Command[1:]...)
Because this context is independent of c.Request.Context(), cancellation of the HTTP request does not propagate to the command's execution context. If a client disconnects or cancels the request while a long-running command is executing, the subprocess may continue running until the configured execution timeout expires.
This can leave unnecessary processes running after the client has abandoned the request, consuming resources and potentially continuing work whose result can no longer be returned.
Steps to Reproduce
- Start the Agentcube PicoD server.
- Send a request to
POST /api/executethat starts a long-running command, with an execution timeout longer than the client wait time. - Cancel the HTTP request or disconnect the client before the command finishes.
- Check whether the subprocess is still running after the request has been cancelled.
Expected Behavior
Cancellation of the incoming HTTP request should cancel the command's execution context, causing the subprocess to be terminated rather than continuing until the configured timeout.
Actual Behavior
The command context is derived from context.Background(), so it does not inherit cancellation from the incoming HTTP request. The subprocess can therefore continue executing after the client disconnects, subject to the configured timeout.
Suggested Fix
Derive the timeout context from the incoming request context:
ctx, cancel := context.WithTimeout(c.Request.Context(), timeoutDuration)
defer cancel()
This allows request cancellation and the configured timeout to propagate through exec.CommandContext.
Relevant Code
pkg/picod/execute.go, around thecontext.WithTimeoutandexec.CommandContextcalls inExecuteHandler.
Additional Context
This is distinct from handling child processes that outlive their direct parent or inherit stdout/stderr pipes. The issue here is specifically that the execution context is not connected to the HTTP request lifecycle.
Verification status: The context construction is confirmed by source inspection. Runtime reproduction of a subprocess surviving client cancellation is still pending.
- Dominant language
- Go
- Stars
- 175
- Forks
- 96
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 9
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from volcano-sh/agentcube
-
Flaky TestGetPrivateKeyPEM in pkg/router due to direct deep equal assertion on rsa.PrivateKeyPossibly taken @0xA8hinav claimed this 183 days ago. Openkind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
volcano-sh/agentcube#348 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 10/100
volcano-sh/agentcube#513 ·
Maintainers usually reply within 1 day
-
router: Start returns before graceful shutdown finishes, so in-flight requests are cut off on SIGTERMPossibly taken @Paramveersingh-S claimed this 3 days ago. Openkind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 52/100
volcano-sh/agentcube#508 ·
Maintainers usually reply within 1 day
-
question
Difficulty 1/5 Under an hour Newbie friendliness 25/100
volcano-sh/agentcube#504 · 1 comment ·
Maintainers usually reply within 1 day
-
Add error-path tests for handleDeleteSandbox to verify Kubernetes and store consistencyPossibly taken @SoumaCloud claimed this 10 days ago. Open
volcano-sh/agentcube#500 · 6 comments · 1 assignee ·
Maintainers usually reply within 1 day
All issues in volcano-sh/agentcube
Similar issues
-
0.kind: bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Judgment-Pack/judgment-pack-runtime#390 ·
Maintainers usually reply within 1 day
-
triage/needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
cozystack/cozystack#5300 · 1 reaction ·
Maintainers usually reply within 2 days
-
bug go
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
teradata-labs/loom#665 ·
Maintainers usually reply within 1 day
-
Improve DB UIOpenenhancement ui/ux
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
jbigler/railswitch#222 ·
Maintainers usually reply within 1 day