JuliaWeb / HTTP.jl

HTTP for Julia
https://juliaweb.github.io/HTTP.jl/stable/
Other
626 stars 177 forks source link

Missed semaphore `Base.release(sem)` after failed `accept` #1143

Open bountyHntr opened 4 months ago

bountyHntr commented 4 months ago
# Servers.jl
function listenloop(f, listener, conns, tcpisvalid,
                       max_connections, readtimeout, access_log, ready_to_accept, verbose)
        sem = Base.Semaphore(max_connections)
        ...
        while isopen(listener)
                try
                    Base.acquire(sem)
                    io = accept(listener)
                    if io === nothing
                        @warnv 1 "unable to accept new connection"
                        continue
                    elseif !tcpisvalid(io)
                        @warnv 1 "!tcpisvalid: $io"
                        close(io)
                        continue
                    end
                    conn = Connection(io)
        ...

There is no Base.release(sem) before continue in the case when something wrong happens when calling accept. As a result, after each continue, semaphore max value decreases.