Skip to content

Commit d8fb4ab

Browse files
committed
add handling of SSL EOF errors
1 parent 846a7aa commit d8fb4ab

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pymongo/asynchronous/pool.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import logging
2121
import os
2222
import socket
23+
import ssl
2324
import sys
2425
import time
2526
import weakref
@@ -1033,7 +1034,10 @@ def _handle_connection_error(self, error: BaseException) -> None:
10331034
assert isinstance(error, AutoReconnect) # Appease type checker.
10341035
# If the original error was a DNS, certificate, or SSL error, ignore it.
10351036
if isinstance(error.__cause__, (_CertificateError, SSLErrors, socket.gaierror)):
1036-
return
1037+
# End of file errors are excluded, because the server may have disconnected
1038+
# during the handshake.
1039+
if not isinstance(error.__cause__, ssl.SSLEOFError):
1040+
return
10371041
error._add_error_label("SystemOverloadedError")
10381042
error._add_error_label("RetryableError")
10391043

pymongo/synchronous/pool.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import logging
2121
import os
2222
import socket
23+
import ssl
2324
import sys
2425
import time
2526
import weakref
@@ -1029,7 +1030,10 @@ def _handle_connection_error(self, error: BaseException) -> None:
10291030
assert isinstance(error, AutoReconnect) # Appease type checker.
10301031
# If the original error was a DNS, certificate, or SSL error, ignore it.
10311032
if isinstance(error.__cause__, (_CertificateError, SSLErrors, socket.gaierror)):
1032-
return
1033+
# End of file errors are excluded, because the server may have disconnected
1034+
# during the handshake.
1035+
if not isinstance(error.__cause__, ssl.SSLEOFError):
1036+
return
10331037
error._add_error_label("SystemOverloadedError")
10341038
error._add_error_label("RetryableError")
10351039

0 commit comments

Comments
 (0)