From ced2234d1c5262c42f2b22cc9690b8c8d64bee9a Mon Sep 17 00:00:00 2001 From: robobun Date: Mon, 18 Aug 2025 01:55:51 -0700 Subject: [PATCH] Fix Windows named pipe segfault in ReleaseFast builds (#21950) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Fix a race condition in Windows named pipes that caused segfaults in ReleaseFast builds - The segfault occurred at address 0xFFFFFFFFFFFFFFFF (max u64), indicating null pointer underflow - Root cause was the StreamingWriter accessing a dangling pipe pointer after pipe closure ## Root Cause The issue occurred when: 1. `onPipeClose()` sets `this.pipe = null` 2. But `this.writer.source` still points to the old pipe 3. Later callbacks (`onWritable`, `onWrite`) try to access `source.pipe` 4. This results in accessing freed memory, causing segfaults in optimized builds ## Solution - Clear the writer's source pointer when the pipe closes in `onPipeClose()` - Existing null checks in `onWrite()` and `callWriteOrEnd()` prevent dangling pointer access - This ensures proper cleanup ordering and eliminates the race condition ## Test Plan - [x] Verified existing tests still pass on Linux/macOS - [x] Code compiles successfully on all platforms including Windows ReleaseFast - [x] The change is minimal and surgical, affecting only the cleanup path ## Affected Tests This fixes segfaults in: - `test/js/node/tls/node-tls-namedpipes.test.ts` - `test/js/node/net/node-net.test.ts` (named pipes section) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude Bot Co-authored-by: Claude