@actions/http-client: a timed-out request is half-closed, never destroyed, so the process can stay alive after all work is done
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- backend
Research direction
Read packages/http-client/src/index.ts, especially HttpClient.requestRawWithCallback and the timeout handler shown in the issue. Reproduce the hang with the supplied repro.mjs against a peer that keeps its side open, then inspect the package’s existing tests for timeout behavior. Done when a timed-out request releases its socket and the process exits in both peer scenarios.
Written by the indexing model from the issue text.
Description
Describe the bug
When a request hits its socket timeout, HttpClient.requestRawWithCallback half-closes the socket and rejects, but never destroys the request or the socket:
// packages/http-client/src/index.ts
req.setTimeout(this._socketTimeout || 3 * 60000, () => {
if (socket) {
socket.end()
}
handleResult(new Error(`Request timeout: ${info.options.path}`))
})
socket.end() sends a FIN and then waits for the peer to close its side. If the peer never does (a stalled upstream, a load balancer that keeps the connection), the socket stays open and referenced, so Node's event loop never becomes empty. The caller gets its rejection, can retry successfully and finish all its work, and the process still does not exit.
This is @actions/http-client 4.0.1 and unchanged on main (0c3a9c3).
To Reproduce
repro.mjs, next to an install of @actions/[email protected]:
// node repro.mjs [closes]
//
// The peer accepts the request and never answers. By default it also keeps its side of the connection open after the
// client's FIN; with "closes" it ends its side when the client does.
import net from 'node:net'
import {HttpClient} from '@actions/http-client'
const peerClosesItsSide = process.argv[2] === 'closes'
const server = net.createServer({allowHalfOpen: !peerClosesItsSide}, socket => {
socket.unref() // the peer's own socket must not be what keeps this process alive
socket.on('data', () => {})
})
server.unref()
server.listen(0, '127.0.0.1', async () => {
const {port} = server.address()
const started = Date.now()
process.on('exit', () => console.log(`process exited ${Date.now() - started} ms after start`))
const client = new HttpClient('repro', [], {socketTimeout: 500, allowRetries: false})
try {
await client.get(`http://127.0.0.1:${port}/`)
} catch (error) {
console.log(`request rejected after ${Date.now() - started} ms: ${error.message}`)
}
console.log('all work is done; the process should exit now')
})
-
npm install @actions/[email protected] -
node repro.mjs: the request is rejected after the timeout, the last line is printed, and the process never exits.request rejected after 504 ms: Request timeout: / all work is done; the process should exit now -
node repro.mjs closes: the same, but the peer closes its side, and the process exits at once.request rejected after 503 ms: Request timeout: / all work is done; the process should exit now process exited 504 ms after start
Expected behavior
After a timeout the request's socket is released, so a process whose work is done exits whatever the peer does.
Replacing socket.end() with socket.destroy() in that handler (or calling req.destroy()) does it. With that one-line change applied to lib/index.js of 4.0.1, node repro.mjs prints process exited 505 ms after start in both cases.
Additional context
How we met it: on self-hosted Linux x64 runners, a step running actions/download-artifact@v8 (9000827, which bundles @actions/http-client 4.0.1) had one request to the artifact service time out, retried, downloaded the artifact, logged its success, and then did not end until the job's time limit cancelled it 52 minutes later. Two jobs of one workflow run did this in the same minutes:
22:45:10.69Z Downloading single artifact
22:51:10.88Z Attempt 1 of 5 failed with error: Request timeout: /twirp/github.actions.results.api.v1.ArtifactService/ListArtifacts. Retrying request in 8000 ms...
22:51:19.24Z Preparing to download the following artifacts:
22:51:21.28Z Artifact download completed successfully.
22:51:21.28Z Total of 1 artifact(s) downloaded
22:51:21.28Z Download artifact has finished successfully
23:43:44.92Z ##[error]The operation was canceled.
We could not inspect the hung processes, so the half-closed socket is the explanation that fits the code and the reproduction above, not something we observed on the runners. download-artifact's run() returns after its success line and nothing calls process.exit, so any handle left open keeps the step alive; when the action is used inside a composite action, the step cannot carry timeout-minutes either.
Related: #2575 describes another socket left open in @actions/artifact, whose wait ends when this same timeout fires after three minutes. With the behaviour described here the timeout itself does not release the socket, so that bound only holds when the peer closes its side.
The reproduction was run with Node v26.11.0 on macOS.
- Dominant language
- TypeScript
- Stars
- 5.9k
- Forks
- 1.8k
- Avg merge
- 15m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- No 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 actions/toolkit
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
@actions/io: `mv(file, dest)` replaces `dest` when it is a symlink to a directory instead of moving into itPossibly taken @bardrop claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
@actions/exec: `exec(commandLine)` drops `""` arguments and trims trailing spaces of the last argumentPossibly taken @bardrop claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
actions/toolkit#2565 · 1 comment ·
Maintainers usually reply within 1 day
-
@actions/cache: downloadCacheHttpClientConcurrent never stops its progress timer on failure, so the step hangs until the job times outPossibly taken @YodHeVauHe claimed this 46 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
Similar issues
-
bug impact:low Team: SecuritySolution Team:Defend Workflows v9.6.0
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
elastic/kibana#306401 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
agentes-chat/agentes-chat#927 ·
Maintainers usually reply within 1 day
-
comp/desktop P2 type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NousResearch/hermes-agent#157702 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
e2e-failure ready-to-code
Difficulty 1/5 Under an hour Newbie friendliness 72/100
redhat-developer/rhdh-plugin-export-overlays#4794 · 1 comment ·
Maintainers usually reply within 1 day