nodejs / nodejs/node

Http client sometimes returns EPIPE when server does not read request body

Open
#38,467 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

http
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

  • Version: v15.12.0
  • Platform: Darwin Kernel Version 20.3.0
What steps will reproduce the bug?
let http = require("http");

let server = http.createServer(async function(req, res)
{
	res.end("ok");
});

(async function()
{
	await new Promise(resolve => server.listen(resolve));
	let buf = Buffer.alloc(50000000);
	for(let i = 0; ; i++)
	{
		let req = http.request({ port: server.address().port, method: "post" }).end(buf);
		let res = await new Promise((resolve, reject) => req.on("response", resolve).on("error", reject));
		let str = "";
		for await (let chunk of res) str += chunk;
		console.log(i, "client received:", str);
	}
}());
How often does it reproduce? Is there a required condition?

Sometimes. It can take a few thousands of iterations or more.

What is the expected behavior?

No EPIPE.

What do you see instead?
85784 client received: ok
node:internal/process/promises:245
          triggerUncaughtException(err, true /* fromPromise */);
          ^

Error: write EPIPE
    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}
Additional information

It does not happen on linux (after more than million iterations).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided HTTP client/server reproduction on Darwin and compare its behavior with Linux. The payload names no source file or test, so trace the HTTP client request-body write path associated with the EPIPE and identify a focused regression test. Done means the reproduction no longer produces EPIPE while the server does not read the request body.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.