nodejs / nodejs/node

Reopen of: Problems with cooperation between http and pipeline/"for await"

Open
#49,429 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Version

v20.5.1

Platform

Darwin Kernel Version 22.6.0

Subsystem

http

What steps will reproduce the bug?

https://github.com/nodejs/node/issues/38262
https://github.com/nodejs/node/issues/38262#issuecomment-991233190

This often stops after the first iteration:

let http = require("http");

let server = http.createServer(async function(req, res)
{
	try
	{
		let len = 0;
		for await (let chunk of req)
		{
			len += chunk.length;
			if(len > 2) throw "payload too large";
		}
		res.end("ok");
	}
	catch(err)
	{
		console.log("server log:", err);
		res.end(err);
	}
});

(async function()
{
	await new Promise(resolve => server.listen(8888, resolve));
	let agent = new http.Agent({ keepAlive: true });
	let data = Buffer.alloc(1000000);
	for(let i = 0; ; i++)
	{
		console.log(i);
		let req = http.request({ port: 8888, method: "post", agent }).end(data);
		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(str);
	}
}());
How often does it reproduce? Is there a required condition?

Often.

What is the expected behavior? Why is that the expected behavior?

It should continue.

What do you see instead?
0
server log: payload too large
payload too large
1
^C

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 supplied reproduction with the reported Node.js version and compare its behavior with issue #38262 and the linked comment. Trace the HTTP request/response async-iterator handling around for await, rejected request processing, and the keep-alive agent. Done means the repeated loop continues reliably after the oversized payload instead of stopping after the first iteration.

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
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.