Skip to content

Commit 9b00835

Browse files
committed
PYTHON-4493 set_write_buffer_limits plus ignore paused writing
1 parent 0c11812 commit 9b00835

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

pymongo/network_layer.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,20 @@ def connection_made(self, transport: BaseTransport) -> None:
503503
The transport argument is the transport representing the write side of the connection.
504504
"""
505505
self.transport = transport # type: ignore[assignment]
506+
self.transport.set_write_buffer_limits(MAX_MESSAGE_SIZE, MAX_MESSAGE_SIZE) # type: ignore
506507

507508
async def write(self, message: bytes) -> None:
508509
"""Write a message to this connection's transport."""
509510
if self.transport.is_closing():
510511
raise OSError("Connection is closed")
512+
try:
513+
self.transport.resume_reading()
514+
# Known bug in SSL Protocols, fixed in Python 3.11: https://github.com/python/cpython/issues/89322
515+
except AttributeError:
516+
raise OSError("connection is already closed") from None
511517
self.transport.write(message)
512-
await self._drain_helper()
513-
self.transport.resume_reading()
518+
# await self._drain_helper()
519+
# self.transport.resume_reading()
514520

515521
async def read(self, request_id: Optional[int], max_message_size: int) -> tuple[bytes, int]:
516522
"""Read a single MongoDB Wire Protocol message from this connection."""
@@ -698,9 +704,9 @@ def pause_writing(self) -> None:
698704
def resume_writing(self) -> None:
699705
assert self._paused
700706
self._paused = False
701-
702-
if self._drain_waiter and not self._drain_waiter.done():
703-
self._drain_waiter.set_result(None)
707+
#
708+
# if self._drain_waiter and not self._drain_waiter.done():
709+
# self._drain_waiter.set_result(None)
704710

705711
def connection_lost(self, exc: Exception | None) -> None:
706712
self._connection_lost = True
@@ -719,15 +725,15 @@ def connection_lost(self, exc: Exception | None) -> None:
719725
else:
720726
self._closed.set_exception(exc)
721727

722-
# Wake up the writer(s) if currently paused.
723-
if not self._paused:
724-
return
725-
726-
if self._drain_waiter and not self._drain_waiter.done():
727-
if exc is None:
728-
self._drain_waiter.set_result(None)
729-
else:
730-
self._drain_waiter.set_exception(exc)
728+
# # Wake up the writer(s) if currently paused.
729+
# if not self._paused:
730+
# return
731+
#
732+
# if self._drain_waiter and not self._drain_waiter.done():
733+
# if exc is None:
734+
# self._drain_waiter.set_result(None)
735+
# else:
736+
# self._drain_waiter.set_exception(exc)
731737

732738
async def _drain_helper(self) -> None:
733739
if self._connection_lost:

0 commit comments

Comments
 (0)