I get the same result with the following code. Note that I can open 2 connections and that the closing of the connection works as expected with a 'close connection' pattern (with one line only with a dot followed by an empty line). It is just that I cannot close the second connection while the first stays open, the 'close connection' pattern is not triggering the close.
let rec accept_connection sock:Unix.file_descr =
let socket_thread = Lwt.return ( Unix.accept sock ) in
let _ = Lwt.bind socket_thread
( fun (fd, caller) ->
ignore(Lwt_io.printf "accepted\n%!");
(*let _ = set_nonblock fd in*)
Lwt.return (readall fd) >>= fun a ->
ignore(Lwt_io.printf "%s\n%!" a);
ignore(Lwt.async (fun () -> Lwt.return (close fd) ) );
Lwt.return 0;
); in
accept_connection sock
let server port =
let inet_addr = inet_addr_any in
let sockaddr = ADDR_INET (inet_addr, port) in
let domain = domain_of_sockaddr sockaddr in
let sock:Unix.file_descr = socket domain SOCK_STREAM 0 in
Unix.bind sock sockaddr;
listen sock 10;
Lwt_main.run ( Lwt.return (accept_connection sock) )