Commits

Dmitry Grebeniuk  committed b30abf6

http server: avoiding double close

  • Participants
  • Parent commits 8a69559

Comments (0)

Files changed (1)

File src/amall_http_server.ml

  (inch, outch)
 : unit
 = IO.run_and_ignore_result
-   (let do_close () =
-      IO.close_in inch >>% fun () ->
-      IO.close_out outch
+   (let closed = ref False in
+    let do_close () =
+      if closed.val
+      then
+        IO.return ()
+      else
+        IO.catch
+          (fun () ->
+             let () = closed.val := True in
+             IO.close_in inch >>% fun () ->
+             IO.close_out outch
+          )
+          (fun e ->
+            let () = dbg "http_server_func: close error: %s"
+              (Printexc.to_string e)
+            in
+              IO.return ()
+          )
     in
     IO.catch
       (fun () ->