Repository navigation
event loop loop forever: make lots of sock_connec at the same time #378
Copy link
Copy link
Closed
Description
- uvloop version: 0.14.0
- Python version: 3.8.3
- Platform: ubuntu 20.04 on wsl2
- Can you reproduce the bug with
PYTHONASYNCIODEBUGin env?: yes - Does uvloop behave differently from vanilla asyncio? How?: yes, asyncio works well
server side: accept connections and do nothing, just close it after a few seconds, simulating heartbeat timeout
client side: connect to server side a lots in the same time, e.g. -c 5000
it succeeded the first time, failed the second time
i cannot even terminate it, it loop forever, all i can do is to kill -9
traceback logs:
01-09 17:00:36.379 ERROR [pid|7281] Exception in callback Loop._sock_connect
handle: <Handle Loop._sock_connect>
Traceback (most recent call last):
File "uvloop/cbhandles.pyx", line 82, in uvloop.loop.Handle._run
File "uvloop/loop.pyx", line 1072, in uvloop.loop.Loop._sock_connect_cb
asyncio.exceptions.InvalidStateError: invalid state
01-09 17:00:36.379 ERROR [pid|7281] Exception in callback Loop._sock_connect
handle: <Handle Loop._sock_connect>
Traceback (most recent call last):
File "uvloop/cbhandles.pyx", line 82, in uvloop.loop.Handle._run
File "uvloop/loop.pyx", line 1072, in uvloop.loop.Loop._sock_connect_cb
asyncio.exceptions.InvalidStateError: invalid state
01-09 17:00:36.379 ERROR [pid|7281] Exception in callback Loop._sock_connect
handle: <Handle Loop._sock_connect>
Traceback (most recent call last):
File "uvloop/cbhandles.pyx", line 82, in uvloop.loop.Handle._run
File "uvloop/loop.pyx", line 1072, in uvloop.loop.Loop._sock_connect_cb
asyncio.exceptions.InvalidStateError: invalid state
01-09 17:00:36.379 ERROR [pid|7281] Exception in callback Loop._sock_connect
handle: <Handle Loop._sock_connect>
Traceback (most recent call last):
File "uvloop/cbhandles.pyx", line 82, in uvloop.loop.Handle._run
File "uvloop/loop.pyx", line 1072, in uvloop.loop.Loop._sock_connect_cb
asyncio.exceptions.InvalidStateError: invalid state
01-09 17:00:36.380 ERROR [pid|7281] Exception in callback Loop._sock_connect
handle: <Handle Loop._sock_connect>
Traceback (most recent call last):
File "uvloop/cbhandles.pyx", line 82, in uvloop.loop.Handle._run
File "uvloop/loop.pyx", line 1072, in uvloop.loop.Loop._sock_connect_cb
asyncio.exceptions.InvalidStateError: invalid state
01-09 17:00:36.380 ERROR [pid|7281] Exception in callback Loop._sock_connect
handle: <Handle Loop._sock_connect>
Traceback (most recent call last):
File "uvloop/cbhandles.pyx", line 82, in uvloop.loop.Handle._run
File "uvloop/loop.pyx", line 1072, in uvloop.loop.Loop._sock_connect_cb
asyncio.exceptions.InvalidStateError: invalid state
01-09 17:00:36.380 ERROR [pid|7281] Exception in callback Loop._sock_connect
handle: <Handle Loop._sock_connect>
Traceback (most recent call last):
File "uvloop/cbhandles.pyx", line 82, in uvloop.loop.Handle._run
File "uvloop/loop.pyx", line 1072, in uvloop.loop.Loop._sock_connect_cb
asyncio.exceptions.InvalidStateError: invalid state
01-09 17:00:36.387 ERROR [pid|7281] Exception in callback Loop._sock_connect
handle: <Handle Loop._sock_connect>
Traceback (most recent call last):
File "uvloop/cbhandles.pyx", line 82, in uvloop.loop.Handle._run
File "uvloop/loop.pyx", line 1072, in uvloop.loop.Loop._sock_connect_cb
asyncio.exceptions.InvalidStateError: invalid state
01-09 17:00:36.387 ERROR [pid|7281] Exception in callback Loop._sock_connect
handle: <Handle Loop._sock_connect>
Traceback (most recent call last):
File "uvloop/cbhandles.pyx", line 82, in uvloop.loop.Handle._run
File "uvloop/loop.pyx", line 1072, in uvloop.loop.Loop._sock_connect_cb
asyncio.exceptions.InvalidStateError: invalid state
01-09 17:00:36.387 ERROR [pid|7281] Exception in callback Loop._sock_connect
handle: <Handle Loop._sock_connect>
Traceback (most recent call last):
File "uvloop/cbhandles.pyx", line 82, in uvloop.loop.Handle._run
File "uvloop/loop.pyx", line 1072, in uvloop.loop.Loop._sock_connect_cb
asyncio.exceptions.InvalidStateError: invalid state
after some checks, seems like the failed sock did not remove the writer correctly(or not in time?)
fut's done_callback is scheduled after the first time loop._sock_connect_cb invoked
at that time related writer is not removed and the socket fd is reused under heavy pressure?
then the same callback is invoked but for different fd?
checked asyncio, it check fut.done(), and uvloop check fut.cancelled()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]event loop [/-][+]event loop loop forever: make lots of sock_connec at the same time[/+]fantix commentedon Jan 21, 2021
Hey, thanks for the report! But please provide a reproducible sample code. I've tried several batches of 10k concurrent connections on the same server but cannot reproduce the issue.
Catstyle commentedon Jan 25, 2021
finally got some time
i wrote some naive codes, just to illustrate the issue
server.py
client.py
concurrency = 1000, works well
concurrency = 5000, oops
using vanilla asyncio, works well
some kernel config
net.core.netdev_max_backlog = 1000
net.ipv4.tcp_max_syn_backlog = 512
Fix future issue in sock_connect()
Fix future issue in sock_connect()
Fix future issue in sock_connect()
Fix future issue in sock_connect()
Fix future issue in sock_connect()