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

Segmentation Fault in HTTP.serve on closed TCP Socket listener #784

Closed
NHDaly opened this issue Dec 7, 2021 · 5 comments
Closed

Segmentation Fault in HTTP.serve on closed TCP Socket listener #784

NHDaly opened this issue Dec 7, 2021 · 5 comments
Labels
bug server About our HTTP server

Comments

@NHDaly
Copy link
Collaborator

NHDaly commented Dec 7, 2021

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
@NHDaly NHDaly changed the title Segmentation Fault in HTTP.serve on closed TCP Socket listener Segmentation Fault in HTTP.serve on closed TCP Socket listener Dec 7, 2021
@NHDaly
Copy link
Collaborator Author

NHDaly commented 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
Copy link
Member

fredrikekre commented Dec 7, 2021

Maybe fixed by JuliaLang/julia#41000 (duplicate of JuliaLang/julia#40993)?

@NHDaly
Copy link
Collaborator Author

NHDaly commented 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
Copy link
Member

Marked for backport.

@fonsp fonsp added bug server About our HTTP server labels Mar 16, 2022
@fredrikekre
Copy link
Member

This should be fixed in Julia by now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug server About our HTTP server
Projects
None yet
Development

No branches or pull requests

3 participants