@@ -1463,20 +1463,20 @@ _dispatch_fd_entry_create_with_fd(dispatch_fd_t fd, uintptr_t hash)
1463
1463
int result = ioctlsocket ((SOCKET )fd , (long )FIONBIO , & value );
1464
1464
(void )dispatch_assume_zero (result );
1465
1465
} else {
1466
- // Try to make writing nonblocking, although pipes not coming
1467
- // from Foundation.Pipe may not have FILE_WRITE_ATTRIBUTES.
1466
+ // The _dispatch_pipe_monitor_thread expects pipes to be
1467
+ // PIPE_WAIT and exploits this assumption by using a blocking
1468
+ // 0-byte read as a synchronization mechanism.
1468
1469
DWORD dwPipeMode = 0 ;
1469
1470
if (GetNamedPipeHandleState ((HANDLE )fd , & dwPipeMode , NULL ,
1470
- NULL , NULL , NULL , 0 ) && !(dwPipeMode & PIPE_NOWAIT )) {
1471
- dwPipeMode |= PIPE_NOWAIT ;
1471
+ NULL , NULL , NULL , 0 ) && !(dwPipeMode & PIPE_WAIT )) {
1472
+ dwPipeMode |= PIPE_WAIT ;
1472
1473
if (!SetNamedPipeHandleState ((HANDLE )fd , & dwPipeMode ,
1473
1474
NULL , NULL )) {
1474
- // We may end up blocking on subsequent writes, but we
1475
- // don't have a good alternative.
1476
- // The WriteQuotaAvailable from NtQueryInformationFile
1477
- // erroneously returns 0 when there is a blocking read
1478
- // on the other end of the pipe.
1479
- _dispatch_fd_entry_debug ("failed to set PIPE_NOWAIT" ,
1475
+ // If setting the pipe to PIPE_WAIT fails, the
1476
+ // monitoring thread will spin constantly, saturating
1477
+ // a core, which is undesirable but non-fatal.
1478
+ // The semantics will still be correct in this case.
1479
+ _dispatch_fd_entry_debug ("failed to set PIPE_WAIT" ,
1480
1480
fd_entry );
1481
1481
}
1482
1482
}
0 commit comments