Skip to content

Commit

Permalink
HACK! Add a 2s delay before changing user to wait for the cohttp serv…
Browse files Browse the repository at this point in the history
…er to be initialized

Cohttp does not return after listening
  • Loading branch information
balat committed Sep 30, 2022
1 parent f2abc32 commit e11dbe8
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/server/ocsigen_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,21 @@ let start ?config () =
with e ->
Lwt_log.ign_error ~section ~exn:e "Cannot create the command pipe"));
(* I change the user for the process *)
(try
(if current_uid = 0
then
match user with None -> () | Some user -> Unix.initgroups user gid);
Unix.setgid gid; Unix.setuid uid
with (Unix.Unix_error _ | Failure _) as e ->
Lwt_log.ign_error ~section "Error: Wrong user or group";
raise e);
Lwt.async (fun () ->
Lwt_unix.sleep 2. >>= fun () ->
(*HACK! This is to wait for the server to be initialized by cohttp.
How to do that in a cleaner way? *)
(try
(if current_uid = 0
then
match user with
| None -> ()
| Some user -> Unix.initgroups user gid);
Unix.setgid gid; Unix.setuid uid
with (Unix.Unix_error _ | Failure _) as e ->
Lwt_log.ign_error ~section "Error: Wrong user or group";
raise e);
Lwt.return ());
let minthreads = Ocsigen_config.get_minthreads ()
and maxthreads = Ocsigen_config.get_maxthreads () in
if minthreads > maxthreads
Expand Down

0 comments on commit e11dbe8

Please sign in to comment.