Skip to content

Commit 321b3e3

Browse files
committed
address review
1 parent 8232f26 commit 321b3e3

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

pymongo/asynchronous/encryption.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,20 @@ async def kms_request(self, kms_context: MongoCryptKmsContext) -> None:
213213
if not data:
214214
raise OSError("KMS connection closed")
215215
kms_context.feed(data)
216-
# Async raises an OSError instead of returning empty bytes
217-
except OSError as err:
218-
raise OSError("KMS connection closed") from err
219216
except MongoCryptError:
220217
raise # Propagate MongoCryptError errors directly.
221218
except Exception as exc:
222219
# Wrap I/O errors in PyMongo exceptions.
223220
if isinstance(exc, BLOCKING_IO_ERRORS):
224221
exc = socket.timeout("timed out")
225-
_raise_connection_failure(address, exc, timeout_details=_get_timeout_details(opts))
222+
# Async raises an OSError instead of returning empty bytes.
223+
if isinstance(exc, OSError):
224+
msg_prefix = "KMS connection closed"
225+
else:
226+
msg_prefix = None
227+
_raise_connection_failure(
228+
address, exc, msg_prefix=msg_prefix, timeout_details=_get_timeout_details(opts)
229+
)
226230
finally:
227231
conn.close()
228232
except MongoCryptError:

pymongo/synchronous/encryption.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,20 @@ def kms_request(self, kms_context: MongoCryptKmsContext) -> None:
213213
if not data:
214214
raise OSError("KMS connection closed")
215215
kms_context.feed(data)
216-
# Async raises an OSError instead of returning empty bytes
217-
except OSError as err:
218-
raise OSError("KMS connection closed") from err
219216
except MongoCryptError:
220217
raise # Propagate MongoCryptError errors directly.
221218
except Exception as exc:
222219
# Wrap I/O errors in PyMongo exceptions.
223220
if isinstance(exc, BLOCKING_IO_ERRORS):
224221
exc = socket.timeout("timed out")
225-
_raise_connection_failure(address, exc, timeout_details=_get_timeout_details(opts))
222+
# Async raises an OSError instead of returning empty bytes.
223+
if isinstance(exc, OSError):
224+
msg_prefix = "KMS connection closed"
225+
else:
226+
msg_prefix = None
227+
_raise_connection_failure(
228+
address, exc, msg_prefix=msg_prefix, timeout_details=_get_timeout_details(opts)
229+
)
226230
finally:
227231
conn.close()
228232
except MongoCryptError:

0 commit comments

Comments
 (0)