Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: fix "unavailable signal" error #420

Merged
merged 2 commits into from
Jan 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib_eio_linux/eio_linux.ml
Original file line number Diff line number Diff line change
@@ -26,9 +26,6 @@ module Suspended = Eio_utils.Suspended
module Zzz = Eio_utils.Zzz
module Lf_queue = Eio_utils.Lf_queue

(* SIGPIPE makes no sense in a modern application. *)
let () = Sys.(set_signal sigpipe Signal_ignore)

type amount = Exactly of int | Upto of int

let system_thread = Ctf.mint_id ()
@@ -1553,3 +1550,8 @@ let rec run : type a.
)
in
Option.get !result

let run ?queue_depth ?n_blocks ?block_size ?polling_timeout ?fallback main =
(* SIGPIPE makes no sense in a modern application. *)
Sys.(set_signal sigpipe Signal_ignore);
run ?queue_depth ?n_blocks ?block_size ?polling_timeout ?fallback main
5 changes: 2 additions & 3 deletions lib_eio_luv/eio_luv.ml
Original file line number Diff line number Diff line change
@@ -21,9 +21,6 @@ module Ctf = Eio.Private.Ctf
module Fiber_context = Eio.Private.Fiber_context
module Lf_queue = Eio_utils.Lf_queue

(* SIGPIPE makes no sense in a modern application. *)
let () = Sys.(set_signal sigpipe Signal_ignore)

type Eio.Exn.Backend.t +=
| Luv_error of Luv.Error.t
| Outside_sandbox of string * string
@@ -1331,6 +1328,8 @@ let stop_signal_thread (tid, omask, outp) =
Unix.sigprocmask SIG_SETMASK omask |> ignore

let run main =
(* Unix's SIGPIPE makes no sense in a modern application. *)
if Sys.os_type = "Unix" then Sys.(set_signal sigpipe Signal_ignore);
let sigctx = start_signal_thread () in
Fun.protect (fun () -> run2 main)
~finally:(fun () -> stop_signal_thread sigctx)
16 changes: 16 additions & 0 deletions tests/flow.md
Original file line number Diff line number Diff line change
@@ -141,3 +141,19 @@ Writing to and reading from a pipe.
+Got: Hello, world
- : unit = ()
```

Make sure we don't crash on SIGPIPE:

```ocaml
# Eio_main.run @@ fun env ->
Switch.run @@ fun sw ->
let r, w = Eio_unix.pipe sw in
Eio.Flow.close r;
try
Eio.Flow.copy_string "Test" w;
assert false
with Eio.Io (Eio.Net.E Connection_reset _, _) ->
traceln "Connection_reset (good)"
+Connection_reset (good)
- : unit = ()
```