|
14 | 14 | # limitations under the License.
|
15 | 15 |
|
16 | 16 |
|
| 17 | +from __future__ import annotations |
| 18 | + |
17 | 19 | import asyncio
|
18 | 20 | import contextlib
|
19 | 21 | import logging
|
@@ -88,14 +90,17 @@ async def _dns_resolver(address, family=0):
|
88 | 90 | type=socket.SOCK_STREAM,
|
89 | 91 | )
|
90 | 92 | except OSError as e:
|
91 |
| - if e.errno in _RETRYABLE_DNS_ERRNOS or ( |
92 |
| - e.errno in _EAI_NONAME |
93 |
| - and (address.host is not None or address.port is not None) |
| 93 | + # note: on some systems like Windows, EAI_NONAME and EAI_NODATA |
| 94 | + # have the same error-code. |
| 95 | + if e.errno in _EAI_NONAME and ( |
| 96 | + address.host is None and address.port is None |
94 | 97 | ):
|
95 |
| - raise ServiceUnavailable( |
96 |
| - f"Failed to DNS resolve address {address}: {e}" |
97 |
| - ) from e |
98 |
| - raise ValueError( |
| 98 | + err_cls = ValueError |
| 99 | + elif e.errno in _RETRYABLE_DNS_ERRNOS or e.errno in _EAI_NONAME: |
| 100 | + err_cls = ServiceUnavailable |
| 101 | + else: |
| 102 | + err_cls = ValueError |
| 103 | + raise err_cls( |
99 | 104 | f"Failed to DNS resolve address {address}: {e}"
|
100 | 105 | ) from e
|
101 | 106 | return list(_resolved_addresses_from_info(info, address._host_name))
|
@@ -179,14 +184,17 @@ def _dns_resolver(address, family=0):
|
179 | 184 | type=socket.SOCK_STREAM,
|
180 | 185 | )
|
181 | 186 | except OSError as e:
|
182 |
| - if e.errno in _RETRYABLE_DNS_ERRNOS or ( |
183 |
| - e.errno in _EAI_NONAME |
184 |
| - and (address.host is not None or address.port is not None) |
| 187 | + # note: on some systems like Windows, EAI_NONAME and EAI_NODATA |
| 188 | + # have the same error-code. |
| 189 | + if e.errno in _EAI_NONAME and ( |
| 190 | + address.host is None and address.port is None |
185 | 191 | ):
|
186 |
| - raise ServiceUnavailable( |
187 |
| - f"Failed to DNS resolve address {address}: {e}" |
188 |
| - ) from e |
189 |
| - raise ValueError( |
| 192 | + err_cls = ValueError |
| 193 | + elif e.errno in _RETRYABLE_DNS_ERRNOS or e.errno in _EAI_NONAME: |
| 194 | + err_cls = ServiceUnavailable |
| 195 | + else: |
| 196 | + err_cls = ValueError |
| 197 | + raise err_cls( |
190 | 198 | f"Failed to DNS resolve address {address}: {e}"
|
191 | 199 | ) from e
|
192 | 200 | return _resolved_addresses_from_info(info, address._host_name)
|
|
0 commit comments