Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions test/issue-1373-default-timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict'

Check failure on line 1 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 22 on ubuntu-latest with WASM SIMD disabled / Test with Node.js 22 on ubuntu-latest

/home/runner/work/undici/undici/test/issue-1373-default-timeout.js

'test timed out after 180000ms'

Check failure on line 1 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 22 on ubuntu-latest / Test with Node.js 22 on ubuntu-latest

/home/runner/work/undici/undici/test/issue-1373-default-timeout.js

'test timed out after 180000ms'

Check failure on line 1 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 22 on macos-latest / Test with Node.js 22 on macos-latest

/Users/runner/work/undici/undici/test/issue-1373-default-timeout.js

'test timed out after 180000ms'

Check failure on line 1 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 22 compiled --without-intl

/home/runner/work/undici/undici/test/issue-1373-default-timeout.js

'test timed out after 180000ms'

// Regression test for https://github.com/nodejs/undici/issues/1373
// Confirms that the default headersTimeout is 300s (not the old 30s).
//
// Uses fake timers (mock.timers) so the test completes instantly —
// no real 35s wait. The clock is fast-forwarded past the old 30s default
// (to 31s) to confirm no HeadersTimeoutError is raised under the 300s default.

const { createServer } = require('node:http')
const { once } = require('node:events')
const { test, mock, after } = require('node:test')
const assert = require('node:assert/strict')
const { Client } = require('..')

test('default headersTimeout is 300s — no timeout at 31s (issue #1373)', async (t) => {

Check failure on line 16 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 26 on ubuntu-latest with WASM SIMD disabled / Test with Node.js 26 on ubuntu-latest

default headersTimeout is 300s — no timeout at 31s (issue #1373)

'test timed out after 180000ms'

Check failure on line 16 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test and Coverage with Node.js 24 on ubuntu-latest / Test and Coverage with Node.js 24 on ubuntu-latest

default headersTimeout is 300s — no timeout at 31s (issue #1373)

'test timed out after 180000ms'

Check failure on line 16 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 25 on ubuntu-latest with WASM SIMD disabled / Test with Node.js 25 on ubuntu-latest

default headersTimeout is 300s — no timeout at 31s (issue #1373)

'test timed out after 180000ms'

Check failure on line 16 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 25 on ubuntu-latest / Test and Coverage with Node.js 25 on ubuntu-latest

default headersTimeout is 300s — no timeout at 31s (issue #1373)

'test timed out after 180000ms'

Check failure on line 16 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 24 on ubuntu-latest with WASM SIMD disabled / Test with Node.js 24 on ubuntu-latest

default headersTimeout is 300s — no timeout at 31s (issue #1373)

'test timed out after 180000ms'

Check failure on line 16 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 26 on ubuntu-latest / Test with Node.js 26 on ubuntu-latest

default headersTimeout is 300s — no timeout at 31s (issue #1373)

'test timed out after 180000ms'

Check failure on line 16 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 26 on macos-latest / Test with Node.js 26 on macos-latest

default headersTimeout is 300s — no timeout at 31s (issue #1373)

'test timed out after 180000ms'

Check failure on line 16 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 25 on macos-latest / Test with Node.js 25 on macos-latest

default headersTimeout is 300s — no timeout at 31s (issue #1373)

'test timed out after 180000ms'

Check failure on line 16 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 24 on macos-latest / Test with Node.js 24 on macos-latest

default headersTimeout is 300s — no timeout at 31s (issue #1373)

'test timed out after 180000ms'

Check failure on line 16 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 24 compiled --without-intl

default headersTimeout is 300s — no timeout at 31s (issue #1373)

'test timed out after 180000ms'

Check failure on line 16 in test/issue-1373-default-timeout.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 25 compiled --without-intl

default headersTimeout is 300s — no timeout at 31s (issue #1373)

'test timed out after 180000ms'
// Enable fake timers before anything else
mock.timers.enable({ apis: ['setTimeout'] })
t.after(() => mock.timers.reset())

const server = createServer((req, res) => {
// Hold the connection open; we'll release it by ticking the fake clock
const timer = setTimeout(() => {
res.writeHead(200, { 'content-type': 'text/plain' })
res.end('ok')
}, 31_000) // 31s — beyond old 30s default, within 300s default

req.on('close', () => clearTimeout(timer))
})

server.listen(0)
await once(server, 'listening')
after(() => server.close())

const { port } = server.address()

const client = new Client(`http://localhost:${port}`)
t.after(() => client.close())

// Start the request (it will hang until the fake clock ticks past 31s)
const responsePromise = new Promise((resolve, reject) => {
client.request({ path: '/', method: 'GET' }, (err, data) => {
if (err) return reject(err)
let body = ''
data.body.on('data', (chunk) => { body += chunk })
data.body.on('end', () => resolve({ status: data.statusCode, body }))
})
})

// Advance fake clock 31 seconds — triggers the server's setTimeout instantly
mock.timers.tick(31_000)

// Should resolve without HeadersTimeoutError (would have failed at 30s old default)
const { status, body } = await responsePromise
assert.equal(status, 200)
assert.equal(body, 'ok')
})

// — Contributed by Milan Soni (SNTL84) · github.com/SNTL84
// — Open to OSS sponsorship & consulting — AI workflows, automation & full-stack builds · desidevloper.com
Loading