nodejs / nodejs/node

When `ReadableStream` read fails, stack trace does not include the line responsible

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

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

web streams
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

Version

22.2.0

Platform
Microsoft Windows NT 10.0.22635.0 x64
Subsystem

No response

What steps will reproduce the bug?

Save the following code to a file and run it:

import net from 'node:net'
import stream from 'node:stream'

const socket = net.connect(90, 'host.invalid.',)
socket.on("error", e => { console.warn("socket error:", e.message) })

let myStream = stream.Duplex.toWeb(socket)

console.log("next line throws")
await myStream.readable.getReader().read()
console.log("this line will never be reached")
How often does it reproduce? Is there a required condition?

No response

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

From the output, you can see there was an error, but you can't see why that crashed the process. The output should mention the line number of the read() call so that the user can add necessary error handling.

Note that --async-stack-traces does not make the output any more useful.

What do you see instead?
> node index.mjs
next line throws
socket error: getaddrinfo ENOTFOUND host.invalid.
node:internal/modules/run_main:115
    triggerUncaughtException(
    ^

Error: getaddrinfo ENOTFOUND host.invalid.
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:120:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'host.invalid.'
}
Additional information

A bad and easy to forget workaround is to wrap each await call.

await reader.read().catch(e => { throw new AggregateError([e]) })

A better workaround might be possible with the (discouraged) async hooks API.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供された index.mjs の再現コードを Node.js 22.2.0 で実行し、ReadableStream reader と stream.Duplex.toWeb(socket) に関係するエラー伝播を調査します。read() 呼び出しのソース位置がキャッチされないエラーに含まれ、失敗する read パスを対象とするリグレッションテストがあることを完了条件とします。

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

評価

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

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

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