nodejs / nodejs/node

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

オープン
#49,429 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

http promises stale stream
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、報告された Node.js バージョンで提供された再現コードを実行し、その動作を issue #38262 およびリンク先のコメントと比較します。for await 周辺の HTTP リクエスト/レスポンスの非同期イテレーター処理、拒否されたリクエストの処理、および keep-alive agent を追跡します。肥大化したペイロードの後も、最初の反復で停止せず、繰り返しループが確実に継続すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
backend, networking
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
52/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。