nodejs / nodejs/node

Stream finished does not always work with http incoming message

未关闭
#38,657 22 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stream
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

  • Version: v15.12.0
  • Platform: Darwin Kernel Version 20.3.0
  • Subsystem: http
What steps will reproduce the bug?

The stream.finished never resolves or rejects when applied onto a destroyed incoming message like in example below. It finishes for example when applied on a destroyed file stream. Also it finishes when the line with await new Promise(r => setTimeout(r, 1000)); is commented. This looks really inconsistent.

let http = require("http");
let { finished } = require("stream/promises");

let server = http.createServer(async function(req, res)
{
	for await (let chunk of req) break;
	await new Promise(r => setTimeout(r, 1000));
	console.log("waiting");
	await finished(req);
	console.log("sending");
	res.end();
});

(async function()
{
	await new Promise(resolve => server.listen(resolve));
	let req = http.request({ port: server.address().port, method: "post" }).end("abc");
	try
	{
		let res = await new Promise((resolve, reject) => req.on("response", resolve).on("error", reject));
		await finished(res.resume());
	}
	catch(e)
	{
		console.log(e);
	}
}());
How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior?
Error: socket hang up
waiting
sending
What do you see instead?
Error: socket hang up
waiting
Additional information

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先在 Node v15.12.0 上运行提供的 http.createServer 复现,并跟踪传入请求、stream/promises 的 finished 函数与延迟的 await 之间的交互。将被销毁请求的行为与报告中所示的文件流行为进行比较。当复现达到 "sending" 并产生预期的 socket hang-up 输出时,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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