@@ -341,6 +341,40 @@ if (!common.isWindows) {
341341 } ) ) ;
342342}
343343
344+ // Reconnecting an adopted pipe BoundSocket after destroy: the adopted handle is
345+ // gone, so pipe-ness must come from the path option rather than the (now null)
346+ // handle, otherwise connect() would wrongly attempt a TCP connect.
347+ if ( ! common . isWindows ) {
348+ const path = `${ common . PIPE } -reconnect` ;
349+
350+ const server = net . createServer ( common . mustCall ( ( socket ) => {
351+ socket . on ( 'data' , ( data ) => socket . end ( data ) ) ;
352+ } , 2 ) ) ;
353+
354+ const bound = new net . BoundSocket ( { path : `${ path } -src` } ) ;
355+ server . listen ( path , common . mustCall ( ( ) => {
356+ const client = new net . Socket ( { handle : bound } ) ;
357+ client . connect ( { path } ) ;
358+ client . once ( 'connect' , common . mustCall ( ( ) => {
359+ client . end ( 'ping' ) ;
360+ client . once ( 'data' , common . mustCall ( ( data ) => {
361+ assert . strictEqual ( data . toString ( ) , 'ping' ) ;
362+ } ) ) ;
363+ client . once ( 'close' , common . mustCall ( ( ) => {
364+ // The adopted handle is gone; reconnect must still be a pipe.
365+ client . connect ( { path } ) ;
366+ client . once ( 'connect' , common . mustCall ( ( ) => {
367+ client . end ( 'pong' ) ;
368+ client . once ( 'data' , common . mustCall ( ( data ) => {
369+ assert . strictEqual ( data . toString ( ) , 'pong' ) ;
370+ } ) ) ;
371+ client . once ( 'close' , common . mustCall ( ( ) => server . close ( ) ) ) ;
372+ } ) ) ;
373+ } ) ) ;
374+ } ) ) ;
375+ } ) ) ;
376+ }
377+
344378// Linux abstract namespace: a leading '\0' binds without creating a filesystem
345379// entry, and still listens/connects.
346380if ( isLinux ) {
0 commit comments