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 sendto not working #319

Closed
stalkerg opened this issue Mar 2, 2020 · 6 comments · Fixed by #332
Closed

udp sendto not working #319

stalkerg opened this issue Mar 2, 2020 · 6 comments · Fixed by #332
Labels

Comments

@stalkerg
Copy link

stalkerg commented Mar 2, 2020

  • uvloop version: 0.14.0
  • Python version: 3.7.6
  • Platform: Linux
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: yes
  • Does uvloop behave differently from vanilla asyncio? How?: not working

Hello. Currently, I am trying to work with aiosip project and it's working very well but unfortunately, it stops working after installing uvloop.
It looks like sendto do nothing and without any error. I can't see any UDP packet on any device.

Probably I should go deeply with gdb.

PS datagram endpoint created fine and without exceptions https://github.com/stalkerg/aiosip/blob/master/aiosip/peers.py#L316

@stalkerg
Copy link
Author

stalkerg commented Mar 2, 2020

with uvloop 0.13.0 I have next error:

  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

in same time with classic eventloop I have no any problems.

@stalkerg
Copy link
Author

stalkerg commented Mar 2, 2020

ok, with version 0.12.2 everything working fine.

@stalkerg
Copy link
Author

stalkerg commented Mar 2, 2020

after bisect I found this commit c2b65bc it's break UDP for aiosip (and I think not only).

@1st1
Copy link
Member

1st1 commented Mar 4, 2020

Thanks for reporting this. Could you please write a functional test that would exhibit the bug?

@stalkerg
Copy link
Author

stalkerg commented Mar 5, 2020

@1st1 yes, please

import asyncio
import uvloop

uvloop.install()


class UDP(asyncio.DatagramProtocol):
    def __init__(self):
        pass

    def connection_lost(self, error):
        print("connection_lost", error)


async def main():
    loop = asyncio.get_event_loop()
    transport, proto = await loop.create_datagram_endpoint(
        lambda: UDP(),
        local_addr=("192.168.1.9", 6001),
        remote_addr=("192.168.1.3", 5060)
    )
    print("Before sending the message without a destination")
    transport.sendto(b"deadbeef")
    await asyncio.sleep(1)
    print("After sending the message without a destination")
    
    print("Before sending the message with a destination")
    transport.sendto(b"deadbeef", ("192.168.1.3", 5060)) # will be connection lost
    await asyncio.sleep(1)
    print("After sending the message with a destination")


asyncio.get_event_loop().run_until_complete(main())

looks like it happens if you trying to send a message with destination address and you have already specified it in create_datagram_endpoint as remote_addr. Without uvloop all working perfectly.

@jlaine
Copy link
Contributor

jlaine commented Mar 5, 2020

You cannot both "connect" the endpoint to a remote address and use sendto() with a destination address.

This is the case in vanilla asyncio too:

https://github.com/python/cpython/blob/85cf1d514b84dc9a4bcb40e20a12e1d82ff19f20/Lib/asyncio/selector_events.py#L1028

I wonder if uvloop is raising ValueError as it should?

EDIT My bad if the same remote address is used for create_datagram_endpoint and sendto it works with vanilla asyncio, so it should work with uvloop too.

@1st1 1st1 added the bug label Mar 11, 2020
fantix added a commit to fantix/uvloop that referenced this issue Apr 10, 2020
fantix added a commit to fantix/uvloop that referenced this issue Apr 10, 2020
fantix added a commit that referenced this issue Apr 11, 2020
This was referenced Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants