Skip to content

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

Closed
@NHDaly

Description

@NHDaly
Collaborator

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

Activity

changed the title [-]Segmentation Fault in HTTP.serve on closed TCP Socket listener[/-] [+]Segmentation Fault in `HTTP.serve` on closed TCP Socket listener[/+] on Dec 7, 2021
NHDaly

NHDaly commented on Dec 7, 2021

@NHDaly
CollaboratorAuthor

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

fredrikekre commented on Dec 7, 2021

@fredrikekre
Member

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

NHDaly

NHDaly commented on Dec 8, 2021

@NHDaly
CollaboratorAuthor

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

fredrikekre commented on Dec 8, 2021

@fredrikekre
Member

Marked for backport.

fredrikekre

fredrikekre commented on Mar 16, 2022

@fredrikekre
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugserverAbout our HTTP server

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @NHDaly@fonsp@fredrikekre

        Issue actions

          Segmentation Fault in `HTTP.serve` on closed TCP Socket listener · Issue #784 · JuliaWeb/HTTP.jl