ocsigen / lwt

OCaml promises and concurrent I/O
https://ocsigen.org/lwt
MIT License
706 stars 172 forks source link

Lwt not handling Ctrl+C correctly when running in Docker #1027

Open maxRN opened 3 weeks ago

maxRN commented 3 weeks ago

The SIGINT (Ctrl+C) signal isn't handled properly when running inside a Docker container.

I would expect when pressing Ctrl+C that the program and then the container exits. Instead, nothing happens and after pressing Ctrl+C three times the container is stopped forcefully (but still running in the background, needs to be killed manually with docker kill)

Reproduction example at https://github.com/maxrn/lwt_test including Docker file, but this is the code I used:

let httpaf_connection_handler sock_addr y =
  let _ = sock_addr in
  let _ = y in
  let%lwt () = Lwt_io.printl "got request!" in
  Lwt_io.eprintl "got request on stderr!"

let x =
  let%lwt listen_address =
    let%lwt addresses = Lwt_unix.getaddrinfo "127.0.0.1" "7654" [] in
    match addresses with
    | [] -> failwith "shouldn't happen"
    | address :: _ -> Lwt.return Lwt_unix.(address.ai_addr)
  in
  let%lwt server =
    Lwt_io.establish_server_with_client_socket listen_address
      httpaf_connection_handler
  in
  let never = fst (Lwt.wait ()) in
  let stop = never in
  let%lwt () = stop in
  Lwt_io.shutdown_server server

let () = Lwt_main.run x

I'm not sure if that's really the most minimal working example, but it's the best I could come up with. It's mostly cobbled together from how Dream uses Lwt internally (where we first encountered the bug)

fyi @aantron

maxRN commented 3 weeks ago

Might be related to #1012?