Skip to content

Commit 846a7aa

Browse files
committed
add handling of dns resolution failures
1 parent 69ae442 commit 846a7aa

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pymongo/asynchronous/pool.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import contextlib
2020
import logging
2121
import os
22+
import socket
2223
import sys
2324
import time
2425
import weakref
@@ -1030,8 +1031,8 @@ def _handle_connection_error(self, error: BaseException) -> None:
10301031
if self.is_sdam or type(error) not in (AutoReconnect, NetworkTimeout):
10311032
return
10321033
assert isinstance(error, AutoReconnect) # Appease type checker.
1033-
# If the original error was a certificate or SSL error, ignore it.
1034-
if isinstance(error.__cause__, (_CertificateError, SSLErrors)):
1034+
# If the original error was a DNS, certificate, or SSL error, ignore it.
1035+
if isinstance(error.__cause__, (_CertificateError, SSLErrors, socket.gaierror)):
10351036
return
10361037
error._add_error_label("SystemOverloadedError")
10371038
error._add_error_label("RetryableError")

pymongo/synchronous/pool.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import contextlib
2020
import logging
2121
import os
22+
import socket
2223
import sys
2324
import time
2425
import weakref
@@ -1026,8 +1027,8 @@ def _handle_connection_error(self, error: BaseException) -> None:
10261027
if self.is_sdam or type(error) not in (AutoReconnect, NetworkTimeout):
10271028
return
10281029
assert isinstance(error, AutoReconnect) # Appease type checker.
1029-
# If the original error was a certificate or SSL error, ignore it.
1030-
if isinstance(error.__cause__, (_CertificateError, SSLErrors)):
1030+
# If the original error was a DNS, certificate, or SSL error, ignore it.
1031+
if isinstance(error.__cause__, (_CertificateError, SSLErrors, socket.gaierror)):
10311032
return
10321033
error._add_error_label("SystemOverloadedError")
10331034
error._add_error_label("RetryableError")

0 commit comments

Comments
 (0)