Skip to content
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

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

Open
misos1 opened this issue Apr 29, 2021 · 4 comments
Open
Labels
http Issues or PRs related to the http subsystem.

Comments

@misos1
Copy link

misos1 commented Apr 29, 2021

  • 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).

@Ayase-252 Ayase-252 added the http Issues or PRs related to the http subsystem. label Apr 30, 2021
@lpinca
Copy link
Member

lpinca commented Apr 30, 2021

This is expected. The server closes the connection via res.end() while the client is still writing data to the socket.

@lpinca
Copy link
Member

lpinca commented Apr 30, 2021

See also #27916.

@misos1
Copy link
Author

misos1 commented Apr 30, 2021

Ok, but then I am not so sure what about was effort around dumping IncomingMessage in case it was not tried to read by something: 3d480dc (maybe this is here to avoid leaks/problems for example for GET requests where the server does not expect a request body?)

@misos1
Copy link
Author

misos1 commented Apr 30, 2021

So is it just coincidence that this generally does not happen on linux?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants