Skip to content

Commit c246df2

Browse files
authored
Merge pull request #12 from krizex/CA-289145
CA-289145: close socket if error occurs when using lwt connect
2 parents 94fa9f6 + b3f805f commit c246df2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/xs_transport_lwt_unix_client.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ let create () =
3434
| Lwt_unix.S_SOCK ->
3535
let sockaddr = Lwt_unix.ADDR_UNIX(path) in
3636
let fd = Lwt_unix.socket Lwt_unix.PF_UNIX Lwt_unix.SOCK_STREAM 0 in
37-
Lwt_unix.connect fd sockaddr >>= fun () ->
37+
Lwt.catch (fun () ->
38+
Lwt_unix.connect fd sockaddr
39+
) (fun e ->
40+
Lwt_unix.close fd >>= fun () -> Lwt.fail e
41+
)
42+
>>= fun () ->
3843
return fd
3944
| _ ->
4045
let fd = Unix.openfile path [ Lwt_unix.O_RDWR ] 0o0 in

0 commit comments

Comments
 (0)