fix: 修复 Node.js 环境下 UDS socket chmod ENOENT 导致进程无输出退出

macOS + Node.js v22 中,嵌套目录路径的 Unix Domain Socket 在
listen 回调触发时文件可能尚未落盘,chmod 随即抛出 ENOENT,
导致 startUdsMessaging → setup() 整条链路崩溃。将 chmod 改为
非致命操作,ENOENT 时安全跳过(父目录已为 0o700)。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-27 20:48:23 +08:00
parent 4266149820
commit c81dac8c3c

View File

@@ -557,7 +557,26 @@ export async function startUdsMessaging(
void (async () => {
try {
if (process.platform !== 'win32') {
await chmod(path, 0o600)
// Restrict socket permissions to owner-only. On macOS with
// Node.js v22, the listen callback may fire before the socket
// file is visible on disk (observed with nested tmpdir paths).
// The parent directory is already 0o700, so skipping chmod when
// the file is not yet visible is safe.
try {
await chmod(path, 0o600)
} catch (err: unknown) {
if (
!(
err instanceof Error &&
(err as NodeJS.ErrnoException).code === 'ENOENT'
)
) {
throw err
}
logForDebugging(
`[udsMessaging] chmod skipped: socket file not yet visible at ${path}`,
)
}
}
srv.off('error', rejectBeforeListen)
srv.on('error', logRuntimeError)