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

Simple RPC client made with dune-rpc-lwt crashes with EBADF #7400

Closed
gridbugs opened this issue Mar 24, 2023 · 2 comments
Closed

Simple RPC client made with dune-rpc-lwt crashes with EBADF #7400

gridbugs opened this issue Mar 24, 2023 · 2 comments

Comments

@gridbugs
Copy link
Collaborator

I tried making a simple example program using dune-rpc-lwt and get an error I don't understand when control reaches the end of the function passed to Dune_rpc_lwt.V1.Client.connect. This might be user error on my part but if that's the case I think we should improve the error message or docs or api to make it clearer what I'm doing wrong.

Expected Behavior

See the example project here: https://github.com/gridbugs/hello-dune-rpc

It connects to a dune rpc server, queries the build dir path which it then prints out, before exiting.

The code is:

module Drpc_lwt = Dune_rpc_lwt.V1
module Drpc = Dune_rpc.V1

let build_dir = "_build"

let () =
  let init = Drpc.Initialize.create ~id:(Drpc.Id.make (Csexp.Atom "hello")) in
  let where = Drpc_lwt.Where.default ~build_dir () in
  print_endline
    (Printf.sprintf "Connecting to server: %s"
       (Dune_rpc_private.Where.to_string where));
  Lwt_main.run
    (let open Lwt.Syntax in
    let open Lwt.Infix in
    let* input_channel, output_channel = Drpc_lwt.connect_chan where in
    Drpc_lwt.Client.connect (input_channel, output_channel) init
      ~f:(fun client ->
        print_endline "client is running";
        let* request =
          Drpc_lwt.Client.Versioned.prepare_request client
            Drpc.Request.build_dir
          >|= Result.get_ok
        in
        let* response =
          Drpc_lwt.Client.request client request () >|= Result.get_ok
        in
        print_endline
          (Printf.sprintf "path is: %s" (Drpc.Path.to_string_absolute response));
        Lwt.return_unit))

If I have dune build -w running in the background then run this program I expect it to connect to the RPC server, print out the build dir, then exit.

Actual Behavior

It connects to the server and prints the build dir, but then raises an exception Unix.Unix_error(Unix.EBADF, "check_descriptor", "").

Full output is:

$ OCAMLRUNPARAM=b _build/default/hello_rpc.exe
Connecting to server: unix:path=_build/.rpc/dune
client is running
path is: _build
Fatal error: exception Unix.Unix_error(Unix.EBADF, "check_descriptor", "")
Raised at Lwt_unix.check_descriptor in file "src/unix/lwt_unix.cppo.ml", line 379, characters 4-64
Called from Lwt_unix.blocking in file "src/unix/lwt_unix.cppo.ml", line 384, characters 2-21
Called from Lwt_unix.read_bigarray in file "src/unix/lwt_unix.cppo.ml", line 682, characters 4-15
Called from Lwt_io.perform_io in file "src/unix/lwt_io.ml", line 236, characters 10-35
Called from Lwt_io.Primitives.read_char in file "src/unix/lwt_io.ml", line 676, characters 6-15
Called from Lwt_io.Primitives.read_char_opt.(fun) in file "src/unix/lwt_io.ml", line 686, characters 17-29
Called from Lwt.Sequential_composition.catch in file "src/core/lwt.ml", line 2008, characters 16-20
Re-raised at Lwt.Miscellaneous.poll in file "src/core/lwt.ml", line 3077, characters 20-29
Called from Lwt_main.run.run_loop in file "src/unix/lwt_main.ml", line 31, characters 10-20
Called from Lwt_main.run in file "src/unix/lwt_main.ml", line 118, characters 8-13
Re-raised at Lwt_main.run in file "src/unix/lwt_main.ml", line 124, characters 4-13
Called from Dune__exe__Hello_rpc in file "hello_rpc.ml", line 12, characters 2-663

Reproduction

See instructions in example project (https://github.com/gridbugs/hello-dune-rpc)

Specifications

  • Version of dune (output of dune --version): 3.7.0
  • Version of ocaml (output of ocamlc --version): 5.0.0
  • Operating system (distribution and version): NixOS
@rgrinberg
Copy link
Member

@gridbugs i believe you fixed this?

@gridbugs
Copy link
Collaborator Author

Ah yep, fixed in #7581

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants