Skip to content

fix(logger): handle EPIPE/ECONNRESET errors on stdout/stderr to prevent process crash#682

Open
icebear0828 wants to merge 1 commit into
devfrom
fix/log-file-epipe-handling
Open

fix(logger): handle EPIPE/ECONNRESET errors on stdout/stderr to prevent process crash#682
icebear0828 wants to merge 1 commit into
devfrom
fix/log-file-epipe-handling

Conversation

@icebear0828

Copy link
Copy Markdown
Owner

问题

容器/pipe 断开时,Node.js 会向 stdout/stderr 发 error 事件,未处理会导致进程崩溃。在 wrap() 里调用原始 write 方法时如果抛 EPIPE,也会上抛给调用方。

修复

  • installFileLogger() 注册 error 事件处理器,静默吞掉 EPIPE / ECONNRESET,其他错误继续 throw
  • uninstall() 时同步 off 解绑,避免 listener 泄漏
  • wrap() 内部的原始 write 调用包 try/catch,抛错时返回 false 而不是崩

测试

  • 新增:write 时 EPIPE 不崩,返回 false
  • 新增:stdout/stderr error 事件 EPIPE/ECONNRESET 不崩
✓ tests/unit/utils/log-file.test.ts (9 tests)

Extracted from #675.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant