nodejs / nodejs/node

`net.Socket({ fd })` can abort the Node.js process when iterating invalid file descriptors

未关闭
#63,308 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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

描述

Version

24.13.1

Platform
Linux KContainer 6.12.86+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.86-1 (2026-05-08) x86_64 x86_64 x86_64 GNU/Linux
Subsystem

net

What steps will reproduce the bug?

Hi,

I found a case where creating net.Socket instances with arbitrary file descriptors can abort the entire Node.js process.

const net = require('net');

let fd = 3;
while (fd < 1000) {
  try {
    const stream = new net.Socket({
      fd: fd,
      readable: false,
      writable: true
    });
    stream.on('error', function () {});
    stream.write('might crash');
  } catch (e) {
    // ignore and continue to next fd
    console.log('caught')
  }
  fd += 1;
}
How often does it reproduce? Is there a required condition?

Reproduces consistently on my system.

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

Invalid or unsupported file descriptors passed to net.Socket({ fd }) should result in ordinary JS exceptions or socket errors, not process abort.

What do you see instead?

Some file descriptors are handled normally and throw JS exceptions that are caught successfully, but eventually Node aborts the process:

root@KContainer:~/git/run/cerebras/node/OPENAI/gpt5.1/filter/batch_3/cross_runtime/temp_deno/3604# node repro.cjs caught caught caught caught 
caught 
caught 
.... 
caught 
caught 
caught 
caught 
caught 
caught 
caught 
caught
Aborted

The abort bypasses JS exception handling entirely.

Additional information

No response

贡献指南

打开贡献指南

从这里开始

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

调研方向

从提供的 JavaScript 复现和 Linux 上的 net.Socket({ fd }) 路径开始,重点关注在 stream.write() 之前如何处理无效描述符。确认该中止可以复现,然后验证无效或不受支持的描述符会产生可捕获的 JavaScript 异常或套接字错误,而不会终止进程。

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

评估

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

把新 issue 发到你的邮箱

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