Skip to content

Conversation

@yawaramin
Copy link
Collaborator

Fix #174

@Willenbrink
Copy link
Collaborator

Looks good!

I was wondering if we should also handle SIGQUIT but that already works. See also this discussion for the common signals to terminate processes. SIGHUP might be interesting at some point.

@Willenbrink Willenbrink self-requested a review September 9, 2025 21:10
@aantron
Copy link
Collaborator

aantron commented Oct 3, 2025

if we should also handle SIGQUIT but that already works

In what context? I have SIGQUIT working in the shell to terminate Dream servers without this PR.

λ dune exec example/1-hello/hello.exe
03.10.25 07:11:33.858                       Running at http://localhost:8080
03.10.25 07:11:33.858                       Type Ctrl+C to stop
^\fish: Job 1, 'dune exec example/1-hello/hello…' terminated by signal SIGQUIT (Quit request from job control with core dump (^\))

But interestingly SIGTERM also also works:

λ dune exec example/1-hello/hello.exe
03.10.25 07:12:58.001                       Running at http://localhost:8080
03.10.25 07:12:58.001                       Type Ctrl+C to stop
^Zfish: Job 1, 'dune exec example/1-hello/hello…' has stopped

λ bg
Send job 1 'dune exec example/1-hello/hello.exe' to background

λ kill %1
λ fish: Job 1, 'dune exec example/1-hello/hello…' terminated by signal SIGTERM (Polite quit request)

This appears to be an issue inside containers. Is SIGQUIT relevant for Dream servers running inside containers?

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).

@yawaramin
Copy link
Collaborator Author

TODO: reconsider approach for multicore.

Don't install the signal handler at the module scope, to avoid polluting
the user's application with potentially unused handlers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

signal handling in dockerfile

4 participants