Skip to content

Commit 3283a4b

Browse files
committed
reduce error when dns fail
1 parent d65ba21 commit 3283a4b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pwnlib/tubes/remote.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ def _connect(self, fam, typ):
113113

114114
async def async_getaddrinfo(host, port, fam=0, typ=0, proto=0, flags=0):
115115
loop = asyncio.get_running_loop()
116-
try:
117-
result = await loop.getaddrinfo(host, port, family=fam, type=typ, proto=proto, flags=flags)
118-
except asyncio.exceptions.CancelledError:
119-
result = []
116+
result = await loop.getaddrinfo(host, port, family=fam, type=typ, proto=proto, flags=flags)
120117
return result
121118

122119
def run_async_in_thread(coro):
@@ -132,8 +129,13 @@ def run_async_in_thread(coro):
132129
def sync_getaddrinfo(*args):
133130
# Run in a separate thread to avoid deadlocks when users nest eventloops.
134131
with concurrent.futures.ThreadPoolExecutor() as executor:
135-
future = executor.submit(run_async_in_thread, async_getaddrinfo(*args))
136-
return future.result()
132+
try:
133+
future = executor.submit(run_async_in_thread, async_getaddrinfo(*args))
134+
return future.result()
135+
except asyncio.exceptions.CancelledError:
136+
return []
137+
except socket.gaierror:
138+
return []
137139

138140
with self.waitfor('Opening connection to %s on port %s' % (self.rhost, self.rport)) as h:
139141
hostnames = sync_getaddrinfo(self.rhost, self.rport, fam, typ, 0, socket.AI_PASSIVE)

0 commit comments

Comments
 (0)