@@ -812,7 +812,7 @@ def test_abort_tolerates_close_failure(self):
812812
813813class TestAbortInflightSockets (unittest .TestCase ):
814814 """_abort_inflight_sockets wakes live pool sockets via
815- shutdown(SHUT_RDWR) and tolerates broken internals."""
815+ shutdown(SHUT_RDWR) + close() and tolerates broken internals."""
816816
817817 def _fake_client_with_stream (self , stream ):
818818 conn = mock .Mock ()
@@ -821,7 +821,7 @@ def _fake_client_with_stream(self, stream):
821821 client ._transport ._pool ._connections = [conn ]
822822 return client
823823
824- def test_shuts_down_live_socket (self ):
824+ def test_shuts_down_and_closes_live_socket (self ):
825825 import socket as _socket
826826
827827 from python_agent_harness .client import _abort_inflight_sockets
@@ -830,7 +830,22 @@ def test_shuts_down_live_socket(self):
830830 stream = mock .Mock ()
831831 stream .get_extra_info .return_value = sock
832832 _abort_inflight_sockets (self ._fake_client_with_stream (stream ))
833+ # shutdown wakes the recv on Linux; close() is the reliable wake
834+ # on macOS/BSD where shutdown alone may leave a parked recv stuck
833835 sock .shutdown .assert_called_once_with (_socket .SHUT_RDWR )
836+ sock .close .assert_called_once_with ()
837+
838+ def test_close_still_runs_when_shutdown_raises (self ):
839+ """A shutdown OSError must not skip the fd close: on macOS the
840+ close is the step that actually wakes the blocked read."""
841+ from python_agent_harness .client import _abort_inflight_sockets
842+
843+ sock = mock .Mock ()
844+ sock .shutdown .side_effect = OSError ("not connected" )
845+ stream = mock .Mock ()
846+ stream .get_extra_info .return_value = sock
847+ _abort_inflight_sockets (self ._fake_client_with_stream (stream )) # no raise
848+ sock .close .assert_called_once_with ()
834849
835850 def test_empty_pool_is_noop (self ):
836851 from python_agent_harness .client import _abort_inflight_sockets
0 commit comments