@actions/http-client: a timed-out request is half-closed, never destroyed, so the process can stay alive after all work is done
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, typescript
- Lĩnh vực
- backend
Hướng nghiên cứu
Đọc packages/http-client/src/index.ts, đặc biệt là HttpClient.requestRawWithCallback và trình xử lý timeout được hiển thị trong issue. Tái hiện tình trạng treo bằng repro.mjs được cung cấp, với một peer giữ kết nối phía mình luôn mở, sau đó kiểm tra các bài kiểm thử hiện có của package về hành vi timeout. Hoàn thành khi một request bị timeout giải phóng socket và tiến trình thoát trong cả hai tình huống peer.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 5.9k
- Fork
- 1.8k
- Merge trung bình
- 15 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của actions/toolkit
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
@actions/io: `mv(file, dest)` replaces `dest` when it is a symlink to a directory instead of moving into itCó thể đã có người làm @bardrop đã nhận 7 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
@actions/exec: `exec(commandLine)` drops `""` arguments and trims trailing spaces of the last argumentCó thể đã có người làm @bardrop đã nhận 7 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
actions/toolkit#2565 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
@actions/cache: downloadCacheHttpClientConcurrent never stops its progress timer on failure, so the step hangs until the job times outCó thể đã có người làm @YodHeVauHe đã nhận 46 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của actions/toolkit
Issue tương tự
-
type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
db-ux-design-system/core-web#8856 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
'!' breaking change is lost when the commit also has an empty BREAKING CHANGE footerCó thể đã có người làm @wittdennis đã nhận hôm nay. Đang mởpriority: p3 type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
googleapis/release-please#2971 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 87/100
Maintainer thường phản hồi trong vòng 1 ngày
-
🛠️ dette technique
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 61/100
betagouv/mon-entreprise#4752 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 5 ngày