Closed
Description
Julia 0.6.4
HTTP v0.9.16
MbedTLS v1.0.3
I have reduced down a segfault that occurs if you try to call HTTP.serve()
with a closed TCP socket listener:
julia> using HTTP, Sockets
julia> router = HTTP.Router();
julia> tcp_server = Sockets.listen(Sockets.localhost, 18000)
Sockets.TCPServer(RawFD(20) active)
julia> close(tcp_server)
julia> HTTP.serve(router, server=tcp_server)
signal (11): Segmentation fault: 11
in expression starting at REPL[6]:1
uv_tcp_getsockname at /workspace/srcdir/libuv/src/unix/tcp.c:290
jl_tcp_getsockname at /Users/nathandaly/src/julia-release/src/jl_uv.c:682
_sockname at /Users/nathandaly/builds/julia-1.6/usr/share/julia/stdlib/v1.6/Sockets/src/Sockets.jl:815
getsockname at /Users/nathandaly/builds/julia-1.6/usr/share/julia/stdlib/v1.6/Sockets/src/Sockets.jl:797 [inlined]
#listen#1 at /Users/nathandaly/work/jl_depots/raicode2/packages/HTTP/qszg7/src/Servers.jl:251
unknown function (ip: 0x1511d2bc8)
listen##kw at /Users/nathandaly/work/jl_depots/raicode2/packages/HTTP/qszg7/src/Servers.jl:248 [inlined]
#serve#3 at /Users/nathandaly/work/jl_depots/raicode2/packages/HTTP/qszg7/src/Handlers.jl:351 [inlined]
serve##kw at /Users/nathandaly/work/jl_depots/raicode2/packages/HTTP/qszg7/src/Handlers.jl:350 [inlined]
serve##kw at /Users/nathandaly/work/jl_depots/raicode2/packages/HTTP/qszg7/src/Handlers.jl:350
unknown function (ip: 0x1511d035f)
...
I recognize that this is not something you should be doing anyway, but it shouldn't segfault.
Can we maybe add a check that might be missing somewhere that the tcp socket server isn't closed yet?
Thanks!
julia> versioninfo()
Julia Version 1.6.4
Commit 35f0c911f4 (2021-11-19 03:54 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin19.6.0)
CPU: Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
JULIA_NUM_THREADS = 4
JULIA_DEPOT_PATH = /Users/nathandaly/work/raicode2/../jl_depots/raicode2
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Segmentation Fault in HTTP.serve on closed TCP Socket listener[/-][+]Segmentation Fault in `HTTP.serve` on closed TCP Socket listener[/+]NHDaly commentedon Dec 7, 2021
Ah, it appears this is a dupe of julia's JuliaLang/julia#29087. We could still consider fixing it in HTTP.jl by adding a check that the server is not closed before calling
getsockname
, so that it will work on older versions of julia, too, but it should certainly be fixed upstream in julia.fredrikekre commentedon Dec 7, 2021
Maybe fixed by JuliaLang/julia#41000 (duplicate of JuliaLang/julia#40993)?
NHDaly commentedon Dec 8, 2021
Ah, excellent. Definitely seems like it has been fixed on 1.7+ 👍 Thanks. Still might be nice for us to check in HTTP.jl to avoid the segfault on older julias, and/or for julia to backport the fix if 1.6 is gonna be the LTS. 👍
fredrikekre commentedon Dec 8, 2021
Marked for backport.
fredrikekre commentedon Mar 16, 2022
This should be fixed in Julia by now.