File tree Expand file tree Collapse file tree 1 file changed +18
-8
lines changed 
src/neo4j/_async_compat/network Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Original file line number Diff line number Diff line change 1515
1616
1717import  asyncio 
18+ import  contextlib 
1819import  logging 
1920import  socket 
2021
@@ -41,12 +42,21 @@ def _resolved_addresses_from_info(info, host_name):
4142            yield  ResolvedAddress (addr , host_name = host_name )
4243
4344
44- _RETRYABLE_DNS_ERRNOS  =  {
45-     socket .EAI_ADDRFAMILY ,
46-     socket .EAI_AGAIN ,
47-     socket .EAI_MEMORY ,
48-     socket .EAI_NODATA ,
49- }
45+ def  _try_get_socket_attributes (* attrs ):
46+     for  attr  in  attrs :
47+         with  contextlib .suppress (AttributeError ):
48+             yield  getattr (socket , attr )
49+ 
50+ 
51+ _RETRYABLE_DNS_ERRNOS  =  set (
52+     _try_get_socket_attributes (
53+         "EAI_ADDRFAMILY" ,
54+         "EAI_AGAIN" ,
55+         "EAI_MEMORY" ,
56+         "EAI_NODATA" ,
57+     )
58+ )
59+ _EAI_NONAME  =  set (_try_get_socket_attributes ("EAI_NONAME" ))
5060
5161
5262class  AsyncNetworkUtil :
@@ -79,7 +89,7 @@ async def _dns_resolver(address, family=0):
7989            )
8090        except  OSError  as  e :
8191            if  e .errno  in  _RETRYABLE_DNS_ERRNOS  or  (
82-                 e .errno  ==   socket . EAI_NONAME 
92+                 e .errno  in   _EAI_NONAME 
8393                and  (address .host  is  not None  or  address .port  is  not None )
8494            ):
8595                raise  ServiceUnavailable (
@@ -170,7 +180,7 @@ def _dns_resolver(address, family=0):
170180            )
171181        except  OSError  as  e :
172182            if  e .errno  in  _RETRYABLE_DNS_ERRNOS  or  (
173-                 e .errno  ==   socket . EAI_NONAME 
183+                 e .errno  in   _EAI_NONAME 
174184                and  (address .host  is  not None  or  address .port  is  not None )
175185            ):
176186                raise  ServiceUnavailable (
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments