Skip to content

Commit c224ee1

Browse files
authored
[backport]Add log when conn_limit_tcp is reached for easy diagnose (#7098)
From Semaphore document: try_acquire s immediately returns false if the value of semaphore s is zero. Otherwise, the value of s is atomically decremented and try_acquire s returns true. (cherry picked from commit 658778f) backport of PR #7092
2 parents 2b42c13 + fff2fbf commit c224ee1

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

ocaml/libs/http-lib/server_io.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ let establish_server ?(signal_fds = []) forker handler sock =
4949
@@ Polly.wait epoll 2 (-1) (fun _ fd _ ->
5050
(* If any of the signal_fd is active then bail out *)
5151
if List.mem fd signal_fds then raise PleaseClose ;
52-
Semaphore.Counting.acquire handler.lock ;
52+
if not (Semaphore.Counting.try_acquire handler.lock) then (
53+
warn "Block %s on accept because the server is busy" handler.name ;
54+
Semaphore.Counting.acquire handler.lock
55+
) ;
5356
let s, caller = Unix.accept ~cloexec:true sock in
5457
try ignore (forker handler s caller)
5558
with exc ->

0 commit comments

Comments
 (0)