Skip to content

Commit 02bd174

Browse files
committed
Fix failing test on macOS 12+ when server closes TCP/IP connection
1 parent c5aa1db commit 02bd174

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
@@ -323,7 +323,7 @@ public function testQueryStaysPendingWhenClientCanNotSendExcessiveMessageInOneCh
323323
public function testQueryStaysPendingWhenClientCanNotSendExcessiveMessageInOneChunkWhenServerClosesSocket()
324324
{
325325
if (PHP_OS === 'Darwin') {
326-
// 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)
326+
// 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)
327327
// Due to this race condition, this is somewhat flaky. Happens around 75% of the time, use `--repeat=100` to reproduce.
328328
// fwrite(): Send of 4260000 bytes failed with errno=41 Protocol wrong type for socket
329329
// @link http://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
@@ -405,9 +405,10 @@ public function testQueryRejectsWhenClientKeepsSendingWhenServerClosesSocketWith
405405
$writePending = $ref->getValue($executor);
406406

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

0 commit comments

Comments
 (0)