@actions/http-client: a timed-out request is half-closed, never destroyed, so the process can stay alive after all work is done
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- node.js, typescript
- Ambito
- backend
Direzione di ricerca
Leggi packages/http-client/src/index.ts, in particolare HttpClient.requestRawWithCallback e il gestore del timeout mostrato nell’issue. Riproduci il blocco con il repro.mjs fornito verso un peer che mantiene aperta la propria connessione, poi esamina i test esistenti del package sul comportamento del timeout. Il lavoro è completato quando una richiesta scaduta rilascia il proprio socket e il processo termina in entrambi gli scenari del peer.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 5.9k
- Fork
- 1.8k
- Merge medio
- 15m
- PR unite (30g)
- 1
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di actions/toolkit
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
@actions/io: `mv(file, dest)` replaces `dest` when it is a symlink to a directory instead of moving into itForse già presa @bardrop l’ha presa 7 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
@actions/exec: `exec(commandLine)` drops `""` arguments and trims trailing spaces of the last argumentForse già presa @bardrop l’ha presa 7 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
actions/toolkit#2565 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
@actions/cache: downloadCacheHttpClientConcurrent never stops its progress timer on failure, so the step hangs until the job times outForse già presa @YodHeVauHe l’ha presa 46 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di actions/toolkit
Issue simili
-
db-d1-sqlite: upsert is aliased to updateOne, so payload.kv.set never inserts new keysForse già presa @pcbeingused333 l’ha presa oggi. ApertaBug db: d1-sqlite Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
payloadcms/payload#19766 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
device-management-toolkit/sample-web-ui#3711 ·
I maintainer di solito rispondono entro 1 giorno
-
bug impact:low Team: SecuritySolution Team:Defend Workflows v9.6.0
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
elastic/kibana#306401 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
agentes-chat/agentes-chat#927 ·
I maintainer di solito rispondono entro 1 giorno
-
Closing a pinned tab jumps to the Tabs section instead of the next open pinned tabForse già presa @seenimohamed l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ardia-browser/ardia#2769 ·
I maintainer di solito rispondono entro 1 giorno