-
Type:
Improvement
-
Resolution: Fixed
-
Priority:
Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
When using pyopenssl, pymongo deals with WantReadError and WantWriteError by polling on the socket like this:
def _call(self, call, *args, **kwargs):
timeout = self.gettimeout()
if timeout:
start = _time.monotonic()
while True:
try:
return call(*args, **kwargs)
except _RETRY_ERRORS: # Includes WantReadError and WantWriteError
self.socket_checker.select(self, True, True, timeout)
if timeout and _time.monotonic() - start > timeout:
raise _socket.timeout("timed out")
continue
Notice that the socket_checker.select includes both read=True and write=True so it will return immediately if the socket is readable or writable. Instead a WantReadError should set read=True and write=False and a WantWriteError should set read=False and write=True. This will avoid a tight loop of calling poll/select when a read or write is required.