@@ -114,53 +114,53 @@ let internal_start ~is_daemon ?waiting_fd monitor_options =
114114
115115 (* ************************ HERE BEGINS THE MAGICAL WORLD OF LWT *********************************)
116116
117- LwtInit. set_engine () ;
118-
119- Lwt. async (LogFlusher. run ~cancel_condition: ExitSignal. signal);
120-
121- (* If `prom` in `Lwt.async (fun () -> prom)` resolves to an exception, this function will be
122- * called *)
123- Lwt. async_exception_hook := (fun exn ->
124- let bt = Printexc. get_backtrace () in
125- let msg = Utils. spf " Uncaught async exception: %s%s"
126- (Printexc. to_string exn )
127- (if bt = " " then bt else " \n " ^ bt)
117+ let initial_lwt_thread () =
118+ Lwt. async (LogFlusher. run ~cancel_condition: ExitSignal. signal);
119+
120+ (* If `prom` in `Lwt.async (fun () -> prom)` resolves to an exception, this function will be
121+ * called *)
122+ Lwt. async_exception_hook := (fun exn ->
123+ let bt = Printexc. get_backtrace () in
124+ let msg = Utils. spf " Uncaught async exception: %s%s"
125+ (Printexc. to_string exn )
126+ (if bt = " " then bt else " \n " ^ bt)
127+ in
128+ Logger. fatal ~exn " Uncaught async exception. Exiting" ;
129+ FlowExitStatus. (exit ~msg Unknown_error )
130+ );
131+
132+ Logger. init_logger
133+ ?log_fd (Hh_logger.Level. min_level () |> lwt_level_of_hh_logger_level);
134+ Logger. info " argv=%s" (argv |> Array. to_list |> String. concat " " );
135+
136+ (* If there is a waiting fd, start up a thread that will message it *)
137+ let handle_waiting_start_command = match waiting_fd with
138+ | None -> Lwt. return_unit
139+ | Some fd ->
140+ let fd = Lwt_unix. of_unix_file_descr ~blocking: true fd in
141+ handle_waiting_start_command fd
128142 in
129- Logger. fatal ~exn " Uncaught async exception. Exiting" ;
130- FlowExitStatus. (exit ~msg Unknown_error )
131- );
132-
133- Logger. init_logger
134- ?log_fd (Hh_logger.Level. min_level () |> lwt_level_of_hh_logger_level);
135- Logger. info " argv=%s" (argv |> Array. to_list |> String. concat " " );
136-
137- (* If there is a waiting fd, start up a thread that will message it *)
138- let handle_waiting_start_command = match waiting_fd with
139- | None -> Lwt. return_unit
140- | Some fd ->
141- let fd = Lwt_unix. of_unix_file_descr ~blocking: true fd in
142- handle_waiting_start_command fd
143- in
144143
145- (* Don't start the server until we've set up the threads to handle the waiting channel *)
146- Lwt. async (fun () ->
147- let % lwt () = handle_waiting_start_command in
148- FlowServerMonitorServer. start monitor_options
149- );
150-
151- (* We can start up the socket acceptor even before the server starts *)
152- Lwt. async (fun () ->
153- SocketAcceptor. run
154- (Lwt_unix. of_unix_file_descr ~blocking: true monitor_socket_fd)
155- monitor_options.FlowServerMonitorOptions. autostop
156- );
157- Lwt. async (fun () ->
158- SocketAcceptor. run_legacy (Lwt_unix. of_unix_file_descr ~blocking: true legacy_socket_fd)
159- );
160-
161- (* Wait forever! Mwhahahahahaha *)
162- Lwt. wait () |> fst
163- |> Lwt_main. run
144+ (* Don't start the server until we've set up the threads to handle the waiting channel *)
145+ Lwt. async (fun () ->
146+ let % lwt () = handle_waiting_start_command in
147+ FlowServerMonitorServer. start monitor_options
148+ );
149+
150+ (* We can start up the socket acceptor even before the server starts *)
151+ Lwt. async (fun () ->
152+ SocketAcceptor. run
153+ (Lwt_unix. of_unix_file_descr ~blocking: true monitor_socket_fd)
154+ monitor_options.FlowServerMonitorOptions. autostop
155+ );
156+ Lwt. async (fun () ->
157+ SocketAcceptor. run_legacy (Lwt_unix. of_unix_file_descr ~blocking: true legacy_socket_fd)
158+ );
159+
160+ (* Wait forever! Mwhahahahahaha *)
161+ Lwt. wait () |> fst
162+ in
163+ LwtInit. run_lwt initial_lwt_thread
164164
165165let daemon_entry_point =
166166 FlowServerMonitorDaemon. register_entry_point (internal_start ~is_daemon: true )
0 commit comments