summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2021-07-20 17:26:48 +0700
committerDaniil Baturin <daniil@baturin.org>2021-07-20 17:26:48 +0700
commitf78478dc4a712010f4fb233a844127911bb9b396 (patch)
tree0af8e0f86f57709ad1a853abc857d62d34c9fa4e /src
parentedf7b78a73fa6481f7b72742a05f41f55833dfae (diff)
downloaduncron-f78478dc4a712010f4fb233a844127911bb9b396.tar.gz
uncron-f78478dc4a712010f4fb233a844127911bb9b396.zip
Close out channels after sending replies
to prevent stale connections from accumulating and running out of the maximum open files limit.
Diffstat (limited to 'src')
-rw-r--r--src/uncron.ml6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/uncron.ml b/src/uncron.ml
index 870fc7e..7040774 100644
--- a/src/uncron.ml
+++ b/src/uncron.ml
@@ -43,14 +43,16 @@ let rec handle_connection ic oc () =
match msg with
| Some msg ->
let reply = handle_message msg in
- Lwt_io.write_line oc reply >>= handle_connection ic oc
+ let%lwt () = Lwt_io.write_line oc reply in
+ let%lwt () = Lwt_io.flush oc in
+ Lwt_io.close oc
| None -> Logs_lwt.info (fun m -> m "Connection closed") >>= return)
let accept_connection conn =
let fd, _ = conn in
let ic = Lwt_io.of_fd Lwt_io.Input fd in
let oc = Lwt_io.of_fd Lwt_io.Output fd in
- Lwt.on_failure (handle_connection ic oc ()) (fun e -> Logs.err (fun m -> m "%s" (Printexc.to_string e) ));
+ Lwt.on_failure (handle_connection ic oc ()) (fun e -> Logs.err (fun m -> m "%s" (Printexc.to_string e)));
Logs_lwt.info (fun m -> m "New connection") >>= return
let delete_socket_if_exists sockfile =