Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions python/glide-async/python/glide/glide_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ async def _write_or_buffer_request(self, request: TRequest):
request.callback_idx if isinstance(request, CommandRequest) else 0
)
res_future = self._available_futures.pop(callback_idx, None)
if res_future:
if res_future and not res_future.done():
res_future.set_exception(e)
else:
ClientLogger.log(
Expand All @@ -355,7 +355,10 @@ async def _write_buffered_requests_to_socket(self) -> None:
b_arr = bytearray()
for request in requests:
ProtobufCodec.encode_delimited(b_arr, request)
await self._stream.send(b_arr)
try:
await self._stream.send(b_arr)
except (anyio.ClosedResourceError, anyio.EndOfStream):
raise ClosingError("The communication layer was unexpectedly closed.")

def _encode_arg(self, arg: TEncodable) -> bytes:
"""
Expand Down
23 changes: 23 additions & 0 deletions python/tests/async_tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,29 @@ async def connect_to_client():
# Clean up the main client
await client.close()

@pytest.mark.parametrize("cluster_mode", [True, False])
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
async def test_UDS_socket_connection_failure(self, glide_client: TGlideClient):
"""Test that the client's error handling during UDS socket connection failure"""
assert await glide_client.set("test_key", "test_value") == OK
assert await glide_client.get("test_key") == b"test_value"

# Force close the UDS connection to simulate socket failure
await glide_client._stream.aclose()

# Verify a ClosingError is raised
with pytest.raises(
ClosingError, match="The communication layer was unexpectedly closed"
):
await glide_client.get("test_key")

# Verify the client is closed
with pytest.raises(
ClosingError,
match="Unable to execute requests; the client is closed. Please create a new client.",
):
await glide_client.get("test_key")


@pytest.mark.anyio
class TestCommands:
Expand Down
1 change: 1 addition & 0 deletions python/tests/test_api_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"test_inflight_request_limit",
"test_statistics",
"test_select",
"test_UDS_socket_connection_failure",
],
"sync_only": ["test_sync_fork"],
}
Expand Down
Loading