You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code tries to send a UDP packet to socat -v PIPE udp-recvfrom:9809,fork and then receive the echo response, but it consistently fails.
julia>using Sockets
julia> sock =UDPSocket()
bind(sock, ip"127.0.0.1", 0)
errormonitor(@asyncprintln(String(recv(sock))))
send(sock, ip"127.0.0.1", 9809, "hello")
sleep(1)
close(sock)
Unhandled Task ERROR: EOFError: read end of file
Stacktrace:
[1] try_yieldto(undo::typeof(Base.ensure_rescheduled))
@ Base ./task.jl:958
[2] wait()
@ Base ./task.jl:1022
[3] wait(c::Base.GenericCondition{Base.Threads.SpinLock}; first::Bool)
@ Base ./condition.jl:130
[4] wait
@ ./condition.jl:125 [inlined]
[5] recvfrom(sock::UDPSocket)
@ Sockets ~/.julia/juliaup/julia-1.11.2+0.x64.apple.darwin14/share/julia/stdlib/v1.11/Sockets/src/Sockets.jl:359
[6] recv
@ ~/.julia/juliaup/julia-1.11.2+0.x64.apple.darwin14/share/julia/stdlib/v1.11/Sockets/src/Sockets.jl:324 [inlined]
[7] (::var"#7#8")()
@ Main ./REPL[6]:4
The problem is that the send() "activates" the UDP socket and yields to the async task, and then the recv() notices that the socket is already "active" and skips registering the libuv callback.
I think I have a fix here: https://github.com/subnero1/Sockets. The key change is that I'm calling uv_udp_recv_start() unconditionally and explicitly ignore an EALREADY return code instead of raising an error, see subnero1/Sockets@fc7c537. This seems to work fine in practice, and I'm currently checking with the libuv folks whether this is a sane way of asking about an ongoing UDP receive, see libuv/libuv#4671.
I'd be happy to raise a PR with this change, but before I go through all the PR boilerplate I'd need a few words of encouragement that the proposed change might indeed get accepted. 🙏
The following code tries to send a UDP packet to
socat -v PIPE udp-recvfrom:9809,fork
and then receive the echo response, but it consistently fails.The problem is that the
send()
"activates" the UDP socket and yields to the async task, and then therecv()
notices that the socket is already "active" and skips registering the libuv callback.julia/stdlib/Sockets/src/Sockets.jl
Lines 346 to 350 in 5e9a32e
Original discussion: https://discourse.julialang.org/t/async-udp-socket-usage/
The text was updated successfully, but these errors were encountered: