Skip to content

Commit 3afb26a

Browse files
committed
Fix failing test on macOS 12+ when server closes TCP/IP connection
1 parent 0c55a59 commit 3afb26a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎tests/Query/TcpTransportExecutorTest.php‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public function testQueryStaysPendingWhenClientCanNotSendExcessiveMessageInOneCh
324324
public function testQueryStaysPendingWhenClientCanNotSendExcessiveMessageInOneChunkWhenServerClosesSocket()
325325
{
326326
if (PHP_OS === 'Darwin') {
327-
// Skip on macOS because it exhibits what looks like a kernal race condition when sending excessive data to a socket that is about to shut down (EPROTOTYPE)
327+
// Skip on macOS because it exhibits what looks like a kernel race condition when sending excessive data to a socket that is about to shut down (ECONNRESET, or EPROTOTYPE before macOS 12)
328328
// Due to this race condition, this is somewhat flaky. Happens around 75% of the time, use `--repeat=100` to reproduce.
329329
// fwrite(): Send of 4260000 bytes failed with errno=41 Protocol wrong type for socket
330330
// @link http://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
@@ -406,9 +406,10 @@ public function testQueryRejectsWhenClientKeepsSendingWhenServerClosesSocketWith
406406
$writePending = $ref->getValue($executor);
407407

408408
// We expect an EPIPE (Broken pipe) on second write.
409-
// However, macOS may report EPROTOTYPE (Protocol wrong type for socket) on first write due to kernel race condition.
410-
// fwrite(): Send of 4260000 bytes failed with errno=41 Protocol wrong type for socket
409+
// However, macOS may report ECONNRESET (Connection reset by peer) on first write due to kernel race condition.
410+
// Before macOS 12, this was reported as EPROTOTYPE (Protocol wrong type for socket) instead.
411411
// @link http://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
412+
// @link https://github.com/apple-oss-distributions/xnu/blob/xnu-8019.41.5/bsd/netinet/tcp_usrreq.c#L1093
412413
if ($writePending) {
413414
$executor->handleWritable();
414415
}
@@ -420,7 +421,7 @@ public function testQueryRejectsWhenClientKeepsSendingWhenServerClosesSocketWith
420421
$this->expectException(
421422
\RuntimeException::class,
422423
'Unable to send query to DNS server tcp://' . $address . ' (',
423-
defined('SOCKET_EPIPE') ? (PHP_OS !== 'Darwin' || $writePending ? SOCKET_EPIPE : SOCKET_EPROTOTYPE) : null
424+
defined('SOCKET_EPIPE') ? (PHP_OS !== 'Darwin' || $writePending ? SOCKET_EPIPE : SOCKET_ECONNRESET) : null
424425
);
425426
throw $exception;
426427
}

0 commit comments

Comments
 (0)