Skip to content

"Interrupted system call" when writing in parallel to stdout #788

@wildfield

Description

@wildfield

Hey guys, I've been playing around with Eio and I'm getting this error

Fatal error: exception Eio.Io Unix_error (Interrupted system call, "writev", "")

Here's the reproduction program. It takes a filename argument and reads the same file in parallel while echoing it to stdout. A ~10KB input file would run into this issue.

let ( / ) = Eio.Path.( / )

let read_file file out : unit =
  Eio.Switch.run (fun sw ->
    let file = Eio.Path.open_in ~sw file in
    let reader = Eio.Buf_read.of_flow ~initial_size:1 ~max_size:10000 file in
    Eio.Buf_write.with_flow ~initial_size:10000 out @@ fun writer -> (
      let rec inner () : unit =
        let line = try Some(Eio.Buf_read.line reader) with End_of_file -> None in
        match line with 
        | None -> ()
        | Some line -> (
          Eio.Buf_write.string writer (Printf.sprintf "%s\n" line);
          inner ()
        )
      in
      inner ()
    )
  )

let main env =
  if Array.length Sys.argv < 2 then
    Eio.Flow.copy_string "Expected file name\n" (Eio.Stdenv.stderr env)
  else
    let domain_mgr = (Eio.Stdenv.domain_mgr env) in
    let rec workers (n: int) (acc: (unit -> unit) list) : (unit -> unit) list =
      if n <= 0 then
        acc
      else
        let work = fun () -> read_file (Eio.Stdenv.cwd env / (Sys.argv.(1))) (Eio.Stdenv.stdout env) in
        let spawn = fun () -> Eio.Domain_manager.run domain_mgr work in
        workers (n - 1) (spawn :: acc)
    in
    let worker_list = workers 5 [] in
    ignore (Eio.Fiber.all worker_list)

let () =
  Eio_main.run @@ fun env ->
    main env

My system is Arch Linux with 6.12.1-arch1-1 kernel. My eio version is 1.2

I would personally expect a jumbled output on stdout, but an exception is somewhat unexpected

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions