Use asyncio to avoid blocking tube.remote when DNS resolution fail#2541
Use asyncio to avoid blocking tube.remote when DNS resolution fail#2541tesuji wants to merge 4 commits intoGallopsled:devfrom
tube.remote when DNS resolution fail#2541Conversation
6db693d to
409f491
Compare
tube.remote when DNS resolution fails
when DNS resolution fails.
409f491 to
a7fd893
Compare
BeforeMain process is blocked arounds 28 seconds even when one presses Ctrl-C repeatedly Click to see log with DEBUG
After
Click to see log with DEBUG
|
71c4db2 to
b4daf12
Compare
tube.remote when DNS resolution failstube.remote when DNS resolution fail
|
Good idea. We should add an I'm not sure of the implications of using the asyncio eventloop once. But I think this could break if there already is an event loop and we try to start another one with |
|
That's a good critical point about nested asyncio eventloops. I have 2 plans:
Both plans will make the code more complicated/harder to maintain. Could we have a nice way to avoid the blocking |
|
Can the original problem be solved differently? If you press Ctrl+C and the process still does something, it means the exception handler does too much work, so it might mean there is some |
aba5dc5 to
b9976b6
Compare
I think the default OS resolution timeout (around 30 seconds) is reasonable. Because the main point
Edit: Nope, I was wrong. The script deadlocks when having nested eventloops. run.py
from pwn import *
host, port = ('nc chall.lac.tf 31174').split()[-2:]
port = args.PORT or port
r = remote(host, int(port))
r.close()
info("kinda ok")
import asyncio
async def foo():
return remote(host, int(port))
asyncio.run(foo()) |
5f72213 to
bebe58f
Compare
* Require python 3.7+ for `asyncio.get_running_loop()` * spawn a separate thread to avoid deadlocks
bebe58f to
d65ba21
Compare
I must admit this is the first time I write python code using
asyncio. We probaly need someexperts to review this part.
This PR aims to avoid blocking the main process when DNS resolution fail when called via
sock.getaddrinfointube.remote().Closes #2540.
Related links
loop.getaddrinfo
Testing
N/A.
Target Branch
Could we backport this to the
stablebranch? Main process stuck is kinda sucks.