nodejs / nodejs/node

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

未关闭
#53,858 11 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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

描述

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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 Node.js 22.2.0 运行提供的 index.mjs 复现,并检查 ReadableStream reader 以及 stream.Duplex.toWeb(socket) 中涉及的错误传播。完成标准是,未捕获的错误包含 read() 调用的源位置,并有一个覆盖失败 read 路径的回归测试。

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

评估

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

把新 issue 发到你的邮箱

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