Skip to content

Commit

Permalink
[server] do not crash when client exits before end of compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Feb 1, 2024
1 parent 4c9976c commit 1dec08e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,19 @@ and init_wait_socket ip port =
end
in
let read = fun _ -> (let s = read_loop 0 in Unix.clear_nonblock sin; Some s) in
let write s = ssend sin (Bytes.unsafe_of_string s) in
let close() = Unix.close sin in
let closed = ref false in
let close() =
if not !closed then begin
try Unix.close sin with Unix.Unix_error _ -> trace "Error while closing socket.";
closed := true;
end
in
let write s =
if not !closed then
match Unix.getsockopt_error sin with
| Some _ -> close()
| None -> ssend sin (Bytes.unsafe_of_string s);
in
false, read, write, close
) in
accept

0 comments on commit 1dec08e

Please sign in to comment.