From c44620d7a1b8bd187d18ccbcec819dc4c54cbb04 Mon Sep 17 00:00:00 2001 From: craff Date: Sat, 11 Dec 2021 23:07:06 -1000 Subject: [PATCH] in fact release was missing if exception was raised in accept --- src/Tiny_httpd.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Tiny_httpd.ml b/src/Tiny_httpd.ml index b7fc8ea2..7ceb019f 100644 --- a/src/Tiny_httpd.ml +++ b/src/Tiny_httpd.ml @@ -1185,9 +1185,9 @@ let run (self:t) : (unit,_) result = end; while self.running do (* limit concurrency *) + Sem_.acquire 1 self.sem_max_connections; try let client_sock, _ = Unix.accept sock in - Sem_.acquire 1 self.sem_max_connections; self.new_thread (fun () -> try @@ -1199,8 +1199,9 @@ let run (self:t) : (unit,_) result = raise e ); with e -> + Sem_.release 1 self.sem_max_connections; _debug (fun k -> k - "Unix.accept or Thread.create raised an exception: %s" + "Unix.accept raised an exception: %s" (Printexc.to_string e)) done; Ok ()