Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions example/z-playground/server/playground.ml
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,6 @@ let rec gc ?(initial = true) () =
let () =
Dream.log "Starting playground";

(* Stop when systemd sends SIGTERM. *)
let stop, signal_stop = Lwt.wait () in
Lwt_unix.on_signal Sys.sigterm (fun _signal ->
Lwt.wakeup_later signal_stop ())
|> ignore;

(* Build the base image. *)
Lwt_main.run begin
Lwt_io.(with_file ~mode:Output "Dockerfile" (fun channel ->
Expand Down Expand Up @@ -520,7 +514,7 @@ let () =
Dream.html (Client.html example)
in

Dream.run ~interface:"0.0.0.0" ~port:80 ~stop ~adjust_terminal:false
Dream.run ~interface:"0.0.0.0" ~port:80 ~adjust_terminal:false
@@ Dream.logger
@@ Dream.router [

Expand Down
2 changes: 1 addition & 1 deletion src/dream.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2129,7 +2129,7 @@ val run :
- [~stop] is a promise that causes the server to stop accepting new
requests, and {!Dream.run} to return. Requests that have already entered
the Web application continue to be processed. The default value is a
promise that never resolves.
promise that resolves when the [TERM] signal is received.
- [~error_handler] handles all errors, both from the application, and
low-level errors. See {!section-errors} and example
{{:https://github.com/aantron/dream/tree/master/example/9-error#folders-and-files}
Expand Down
9 changes: 6 additions & 3 deletions src/http/http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,10 @@ let serve_with_maybe_https

let default_interface = "localhost"
let default_port = 8080
let never = fst (Lwt.wait ())
let on_sigterm =
let promise, resolve = Lwt.wait () in
ignore (Lwt_unix.on_signal Sys.sigterm (fun _ -> Lwt.wakeup_later resolve ()));
promise
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating this promise at program init time seems questionable now.

Before, the never promise was a sort of orphan promise in the heap that was fine to have floating around since init time.

But the on_sigterm promise should probably only be created if serve/run are actually called, since a program might end up with Dream linked in but never actually use it. It seems questionable to affect signal handling at init time even if Dream does not end up getting used (or at init time even if Dream does end up getting used).


let network ~port ~socket_path =
match socket_path with
Expand All @@ -679,7 +682,7 @@ let serve
?(interface = default_interface)
?(port = default_port)
?socket_path
?(stop = never)
?(stop = on_sigterm)
?(error_handler = Error_handler.default)
?(tls = false)
?certificate_file
Expand Down Expand Up @@ -707,7 +710,7 @@ let run
?(interface = default_interface)
?(port = default_port)
?socket_path
?(stop = never)
?(stop = on_sigterm)
?(error_handler = Error_handler.default)
?(tls = false)
?certificate_file
Expand Down
Loading