From fb6df124c3d60fb39f32fd98c2dcf66b127cd071 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Thu, 17 Oct 2024 10:59:08 -0700 Subject: [PATCH] PYTHON-4874 Fix async Windows KMS support --- pymongo/network_layer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymongo/network_layer.py b/pymongo/network_layer.py index 7a325853c8..aa16e85a07 100644 --- a/pymongo/network_layer.py +++ b/pymongo/network_layer.py @@ -215,11 +215,11 @@ async def _async_receive_ssl( while total_read < length: try: read = conn.recv_into(mv[total_read:]) + if read == 0: + raise OSError("connection closed") # KMS responses update their expected size after the first batch, stop reading after one loop if once: return mv[:read] - if read == 0: - raise OSError("connection closed") except BLOCKING_IO_ERRORS: await asyncio.sleep(backoff) read = 0