nodejs / nodejs/node

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

未关闭
#49,429 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

http promises stale stream
主要语言
JavaScript
星标
122k
派生
37.3k
平均合并
4 天 2 小时
30 天内合并 PR
283

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,使用报告中提到的 Node.js 版本运行所提供的复现,并将其行为与 issue #38262 及链接的评论进行比较。跟踪 for await 附近的 HTTP 请求/响应异步迭代器处理、被拒绝请求的处理以及 keep-alive agent。完成的标准是:超大 payload 之后,重复循环能够可靠地继续,而不是在第一次迭代后停止。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, node.js
领域
backend, networking
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
52/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。