-
-
Notifications
You must be signed in to change notification settings - Fork 795
docs: add reproduction guide and update bug report template #5451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mcollina
wants to merge
2
commits into
main
Choose a base branch
from
reproduction-guide
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+198
−4
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |||||
| * [Building for externally shared node builtins](#external-builds) | ||||||
| * [Benchmarks](#benchmarks) | ||||||
| * [Documentation](#documentation) | ||||||
| * [Reproduction](#reproduction) | ||||||
| * [Developer's Certificate of Origin 1.1](#developers-certificate-of-origin) | ||||||
| * [Moderation Policy](#moderation-policy) | ||||||
|
|
||||||
|
|
@@ -198,6 +199,157 @@ cd docs && npm i && npm run serve | |||||
|
|
||||||
| The documentation will be available at `http://localhost:3000`. | ||||||
|
|
||||||
| <a id="reproduction"></a> | ||||||
| ### Reproduction | ||||||
|
|
||||||
| When reporting a bug, a high-quality reproduction helps maintainers diagnose and fix the issue quickly. Follow the guidelines below to create a minimal, standalone reproduction script. | ||||||
|
|
||||||
| #### What Makes a Good Reproduction | ||||||
|
|
||||||
| - **Standalone**: The script must be self-contained and run without external dependencies beyond `undici` and Node.js built-in modules. | ||||||
| - **Minimal**: Strip everything unrelated to the bug — no production configs, no frameworks, no unnecessary middleware. | ||||||
| - **Reproducible**: Run the script and confirm the bug occurs before submitting. | ||||||
| - **Specific**: Include the exact `undici` API call that triggers the issue (e.g., `Client`, `Pool`, `Agent`, `fetch`, `request`, `stream`, `pipeline`). | ||||||
| - **Run with Node's test runner**: Use `node --test` (Node 20+) or `node test/your-repro.js`. | ||||||
|
|
||||||
| #### Standalone Server Pattern | ||||||
|
|
||||||
| Use `createServer` from `node:http` (or `node:https` for TLS-related bugs) to run a local server inside the same script. This avoids external service dependencies and keeps the reproduction fully self-contained. | ||||||
|
|
||||||
| ```javascript | ||||||
| 'use strict' | ||||||
|
|
||||||
| const { test, after } = require('node:test') | ||||||
| const { createServer } = require('node:http') | ||||||
| const { once } = require('node:events') | ||||||
| const { Client, errors } = require('undici') | ||||||
|
|
||||||
| // https://github.com/nodejs/undici/issues/XXXX | ||||||
|
|
||||||
| test('short description of the bug', { timeout: 60000 }, async (t) => { | ||||||
| const { tspl } = require('@matteo.collina/tspl') | ||||||
| t = tspl(t, { plan: 1 }) | ||||||
|
|
||||||
| // 1. Start a local HTTP server that reproduces the scenario | ||||||
| const server = createServer({ joinDuplicateHeaders: true }, async (req, res) => { | ||||||
| // Simulate the bug-triggering response | ||||||
| res.statusCode = 200 | ||||||
| res.setHeader('content-length', 100) | ||||||
| res.end('hello'.repeat(20)) | ||||||
| }) | ||||||
| after(() => { server.closeAllConnections?.(); server.close() }) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use t.after instead of global import
Suggested change
Ditto at other places |
||||||
|
|
||||||
| server.listen(0) | ||||||
| await once(server, 'listening') | ||||||
|
|
||||||
| // 2. Create the undici client pointing to the local server | ||||||
| const client = new Client(`http://localhost:${server.address().port}`) | ||||||
| after(() => client.close()) | ||||||
|
|
||||||
| // 3. Perform the request that triggers the bug | ||||||
| client.request({ path: '/', method: 'GET' }, (err, data) => { | ||||||
| t.ifError(err) | ||||||
|
|
||||||
| let body = '' | ||||||
| data.body.on('data', (chunk) => { body += chunk }) | ||||||
| data.body.on('end', () => { | ||||||
| t.strictEqual(body, 'hello'.repeat(20)) | ||||||
| }) | ||||||
| }) | ||||||
| }) | ||||||
| ``` | ||||||
|
|
||||||
| Save the script as `test/repro-XXXX.js` and run it: | ||||||
|
|
||||||
| ```bash | ||||||
| node --test test/repro-XXXX.js | ||||||
| ``` | ||||||
|
|
||||||
| #### Fetch-Based Reproduction | ||||||
|
|
||||||
| For bugs involving `fetch`, use the same standalone server pattern: | ||||||
|
|
||||||
| ```javascript | ||||||
| 'use strict' | ||||||
|
|
||||||
| const { test, after } = require('node:test') | ||||||
| const { createServer } = require('node:http') | ||||||
| const { once } = require('node:events') | ||||||
| const { fetch, Agent, setGlobalDispatcher } = require('undici') | ||||||
|
|
||||||
| // https://github.com/nodejs/undici/issues/XXXX | ||||||
|
|
||||||
| test('short description of the fetch bug', { timeout: 60000 }, async (t) => { | ||||||
| const { tspl } = require('@matteo.collina/tspl') | ||||||
| t = tspl(t, { plan: 1 }) | ||||||
|
|
||||||
| const server = createServer({ joinDuplicateHeaders: true }, async (req, res) => { | ||||||
| res.statusCode = 200 | ||||||
| res.setHeader('content-type', 'application/json') | ||||||
| res.end(JSON.stringify({ ok: true })) | ||||||
| }) | ||||||
| after(() => server.close()) | ||||||
|
|
||||||
| server.listen(0) | ||||||
| await once(server, 'listening') | ||||||
|
|
||||||
| const agent = new Agent({ keepAliveTimeout: 1 }) | ||||||
| after(() => agent.close()) | ||||||
|
|
||||||
| const response = await fetch(`http://localhost:${server.address().port}/`, { | ||||||
| dispatcher: agent | ||||||
| }) | ||||||
|
|
||||||
| t.strictEqual(response.status, 200) | ||||||
| }) | ||||||
| ``` | ||||||
|
|
||||||
| #### Using Pool or Agent | ||||||
|
|
||||||
| For bugs involving connection pooling or agent behavior: | ||||||
|
|
||||||
| ```javascript | ||||||
| 'use strict' | ||||||
|
|
||||||
| const { test, after } = require('node:test') | ||||||
| const { createServer } = require('node:http') | ||||||
| const { once } = require('node:events') | ||||||
| const { Pool } = require('undici') | ||||||
|
|
||||||
| // https://github.com/nodejs/undici/issues/XXXX | ||||||
|
|
||||||
| test('Pool bug reproduction', { timeout: 60000 }, async (t) => { | ||||||
| const { tspl } = require('@matteo.collina/tspl') | ||||||
| t = tspl(t, { plan: 1 }) | ||||||
|
|
||||||
| const server = createServer({ joinDuplicateHeaders: true }, (req, res) => { | ||||||
| res.end('ok') | ||||||
| }) | ||||||
| after(() => server.close()) | ||||||
|
|
||||||
| server.listen(0) | ||||||
| await once(server, 'listening') | ||||||
|
|
||||||
| const pool = new Pool(`http://localhost:${server.address().port}`) | ||||||
| after(() => pool.close()) | ||||||
|
|
||||||
| const data = await pool.request({ path: '/', method: 'GET' }) | ||||||
| t.strictEqual(data.statusCode, 200) | ||||||
| }) | ||||||
| ``` | ||||||
|
|
||||||
| #### Adding the Reproduction to the Repository | ||||||
|
|
||||||
| If you are submitting a bug fix via a pull request, include a test file `test/issue-XXXX.js` that reproduces the bug and passes with the fix. | ||||||
|
|
||||||
| #### Checklist for Submitting a Bug Report | ||||||
|
|
||||||
| 1. [ ] Write a standalone reproduction script. | ||||||
| 2. [ ] Run it locally to confirm the bug is reproducible. | ||||||
| 3. [ ] Attach the script (or a gist link) in the bug report. | ||||||
| 4. [ ] Include the exact undici version and Node.js version. | ||||||
| 5. [ ] Describe the expected vs. actual behavior. | ||||||
|
|
||||||
| <a id="developers-certificate-of-origin"></a> | ||||||
| ## Developer's Certificate of Origin 1.1 | ||||||
|
|
||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we recommend t.plan instead of tspl?
Ditto in other occurrences.