Skip to content

Commit ee1f308

Browse files
committed
Test edge case where get_buffer is called with a sizehint of 0 on SSL
1 parent 2aff6b1 commit ee1f308

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pymongo/network_layer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ def settimeout(self, timeout: float | None) -> None:
419419
self.conn[1].settimeout(timeout)
420420

421421
async def close(self) -> None:
422+
# print(f"Closing network interface from {''.join(traceback.format_stack())}")
422423
self.conn[0].abort()
423424
await self.conn[1].wait_closed()
424425

@@ -528,8 +529,10 @@ async def read(self, request_id: Optional[int], max_message_size: int) -> tuple[
528529
self._start_index = 0
529530
self._op_code = None # type: ignore[assignment]
530531
self._overflow = None
532+
self._is_compressed = False
533+
self._compressor_id = None
531534
if self.transport and self.transport.is_closing():
532-
raise OSError("Connection is closed")
535+
raise OSError("connection is already closed")
533536
read_waiter = asyncio.get_running_loop().create_future()
534537
self._pending_messages.append(read_waiter)
535538
try:
@@ -581,6 +584,9 @@ def get_buffer(self, sizehint: int) -> memoryview:
581584
If any data does not fit into the returned buffer, this method will be called again until
582585
either no data remains or an empty buffer is returned.
583586
"""
587+
# TODO: This is super hacky and is purely for debugging purposes
588+
if sizehint == 0:
589+
return memoryview(bytearray(256))
584590
if self._overflow is not None:
585591
return self._overflow[self._overflow_index :]
586592
return self._buffer[self._end_index :]

0 commit comments

Comments
 (0)