]> matita.cs.unibo.it Git - helm.git/blobdiff - daemons/http_getter/main.ml
ensure connections get closed after having been served
[helm.git] / daemons / http_getter / main.ml
index c200c161dbe931a2a6c04f719dae3b12f1cab3fe..572e9de1b932419203400a630186111002fec218 100644 (file)
@@ -263,7 +263,7 @@ let respond_xslt patch_xslt xslt_name outchan =
 
   (* thread action *)
 
-let callback (req: Http_types.request) outchan =
+let callback ((req: Http_types.request), outchan) =
   try
     Http_getter_logger.log ("Connection from " ^ req#clientAddr);
     Http_getter_logger.log ("Received request: " ^ req#uri);
@@ -334,6 +334,11 @@ let callback (req: Http_types.request) outchan =
           log_failure msg;
           return_html_error ("uncaught_exception", msg) msg outchan)
 
+let callback req outchan =
+  HExtlib.finally
+    (fun () -> try close_out outchan with Sys_error _ -> ())
+    callback (req, outchan)
+
 let batch_update = ref false      
 
 let args = [ ]