Skip to content

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

Description

@misos1

Version

v20.5.1

Platform

Darwin Kernel Version 22.6.0

Subsystem

http

What steps will reproduce the bug?

#38262
#38262 (comment)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpIssues and PRs related to the http subsystem.promisesIssues and PRs related to ECMAScript promises.streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions