@@ -97,12 +97,12 @@ export const readBootstrapEnvelope = Effect.fn("readBootstrapEnvelope")(function
9797 timeoutMs ?: number ;
9898 } ,
9999) : Effect . fn . Return < A , BootstrapError > {
100- yield * Effect . try ( {
100+ const stat = yield * Effect . try ( {
101101 try : ( ) => NodeFS . fstatSync ( fd ) ,
102102 catch : ( cause ) => new BootstrapFdStatError ( { fd, cause } ) ,
103103 } ) ;
104104
105- const stream = yield * makeBootstrapInputStream ( fd ) ;
105+ const stream = yield * makeBootstrapInputStream ( fd , stat . isSocket ( ) || stat . isFIFO ( ) ) ;
106106
107107 // Covers slow cold starts while staying well under the desktop readiness timeout.
108108 const timeoutMs = options ?. timeoutMs ?? 30_000 ;
@@ -175,11 +175,17 @@ export const readBootstrapEnvelope = Effect.fn("readBootstrapEnvelope")(function
175175
176176const makeBootstrapInputStream = Effect . fn ( "bootstrap.makeBootstrapInputStream" ) ( function * (
177177 fd : number ,
178+ isPipe : boolean ,
178179) {
179180 const platform = yield * HostProcess . Platform ;
180- const fdPath = resolveFdPath ( fd , platform ) ;
181+ const fdPath = isPipe ? undefined : resolveFdPath ( fd , platform ) ;
181182 return yield * Effect . try < NodeStream . Readable , BootstrapInputStreamOpenError > ( {
182183 try : ( ) => {
184+ // fs reads of an empty non-blocking pipe fail with EAGAIN, and blocking ones pin a
185+ // threadpool thread past the timeout; a libuv stream waits for data and destroys cleanly.
186+ if ( isPipe ) {
187+ return makeSocketBootstrapStream ( fd ) ;
188+ }
183189 if ( fdPath === undefined ) {
184190 return makeDirectBootstrapStream ( fd ) ;
185191 }
@@ -212,22 +218,21 @@ const makeBootstrapInputStream = Effect.fn("bootstrap.makeBootstrapInputStream")
212218 } ) ;
213219} ) ;
214220
215- const makeDirectBootstrapStream = ( fd : number ) : NodeStream . Readable => {
216- try {
217- return NodeFS . createReadStream ( "" , {
218- fd,
219- encoding : "utf8" ,
220- autoClose : true ,
221- } ) ;
222- } catch {
223- const stream = new NodeNet . Socket ( {
224- fd,
225- readable : true ,
226- writable : false ,
227- } ) ;
228- stream . setEncoding ( "utf8" ) ;
229- return stream ;
230- }
221+ const makeDirectBootstrapStream = ( fd : number ) : NodeStream . Readable =>
222+ NodeFS . createReadStream ( "" , {
223+ fd,
224+ encoding : "utf8" ,
225+ autoClose : true ,
226+ } ) ;
227+
228+ const makeSocketBootstrapStream = ( fd : number ) : NodeStream . Readable => {
229+ const stream = new NodeNet . Socket ( {
230+ fd,
231+ readable : true ,
232+ writable : false ,
233+ } ) ;
234+ stream . setEncoding ( "utf8" ) ;
235+ return stream ;
231236} ;
232237
233238// WSL-inherited stdin pipes cannot be reopened via /proc/self/fd/0 (EACCES),
0 commit comments