Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDP connection fails when local_addr and remote_addr are used together #276

Closed
primal100 opened this issue Oct 15, 2019 · 3 comments · Fixed by #291
Closed

UDP connection fails when local_addr and remote_addr are used together #276

primal100 opened this issue Oct 15, 2019 · 3 comments · Fixed by #291

Comments

@primal100
Copy link

  • uvloop version: 0.13.0
  • Python version: 3.7.4
  • Platform: Ubuntu
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: Yes

The following code, using local_addr and remote_addr together:

import asyncio
try:
    import uvloop
    uvloop.install()
except ImportError:
    uvloop = None


server_addr = ('127.0.0.1', 8888)
client_addr = ('127.0.0.1', 0)


async def run():
    print(asyncio.get_event_loop())
    server_transport, client_protocol = await asyncio.get_event_loop().create_datagram_endpoint(asyncio.DatagramProtocol,
                                                                              local_addr=server_addr)
    print('SERVER RUNNING')
    client_transport, client_conn = await asyncio.get_event_loop().create_datagram_endpoint(asyncio.DatagramProtocol,
                                                                              remote_addr=server_addr,
                                                                              local_addr=client_addr)
    client_transport.close()
    print('CLIENT DONE')
    server_transport.close()
    print('SERVER STOPPED')

if __name__ == '__main__':
    asyncio.run(run())

produces the following error:

<uvloop.Loop running=True closed=False debug=False>
Traceback (most recent call last):
  File "scratch_144.py", line 35, in <module>
    asyncio.run(run())
  File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "uvloop/loop.pyx", line 1417, in uvloop.loop.Loop.run_until_complete
  File "scratch_144.py", line 29, in run
    await run_client()
  File "scratch_144.py", line 20, in run_client
    transport, conn = await asyncio.get_event_loop().create_datagram_endpoint(asyncio.DatagramProtocol, remote_addr=server_addr, local_addr=client_addr)
  File "uvloop/loop.pyx", line 2980, in create_datagram_endpoint
  File "uvloop/handles/udp.pyx", line 86, in uvloop.loop.UDPTransport._connect
OSError: [Errno 106] Transport endpoint is already connected

If I remove the local_addr argument from the second create_datagram_endpoint, it works.
The above example works ok in Selector and Proactor.

@jlaine
Copy link
Contributor

jlaine commented Oct 18, 2019

The code in create_datagram_endpoint indeed looks suspicious, there are two calls to _connect:

udp._connect(rai.ai_addr, rai.ai_addrlen)

udp._connect(rai.ai_addr, rai.ai_addrlen)

@1st1
Copy link
Member

1st1 commented Oct 25, 2019

Yeah, weird. Probably was a remnant of the old UDP implementation surfaced because of the three-way merge I had to do.

@1st1
Copy link
Member

1st1 commented Oct 25, 2019

I've just published https://github.com/MagicStack/uvloop/releases/tag/v0.14.0rc1. Please test. The final release will be published some time next week if RC1 is OK.

@1st1 1st1 closed this as completed Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants