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

Invalid capability index! when trying to return a capability reference from the server to the client. #270

Closed
RyanGibb opened this issue Mar 9, 2023 · 2 comments

Comments

@RyanGibb
Copy link

RyanGibb commented Mar 9, 2023

I've followed the tutorial in the README, and am trying to adapt it to define a schema that has a Connection.create method which returns a Connection.Stream:

@0xdcaa43aa8c57d4a8;

interface Connection {
  create @0 () -> (stream :Stream);
  interface Stream {
    read @0 () -> (data :Data);
    write @1 (data :Data) -> ();
    close @2 () -> ();
  }
}

My create implementation instantiates a Stream and returns it as a result:

      method create_impl _params release_param_caps =
        let open Connection.Create in
        release_param_caps ();
        let stream = Stream.local in
        let response, results = Service.Response.create Results.init_pointer in
        Results.stream_set results (Some stream);
        Service.return response

The client calls this with:

  let create t =
    let open Api.Client.Connection.Create in
    let request, _params = Capability.Request.create Params.init_pointer in
    Capability.call_for_value_exn t method_id request |> Results.stream_get

However when I try to use the resulting Capability.t stream I get the exception: Invalid capability index!.

I've checked the reference counting, and it appears to be 2 after Results.stream_set results (Some stream);.

The full example can be found here, with the relevant files being:

The output of which is:

Connection(rc=1)
Stream(rc=1)
Stream(rc=2)
Failed: Invalid capability index!
Failed: Invalid capability index!

Does the capability need to be a sturdy ref in order to be passed to the client?

I'm using the EIO port.

@avsm
Copy link
Member

avsm commented Mar 9, 2023

Not had a chance to look at your code yet, but here's an older repository that has a similar setup (client/server+callbacks) that did work a few years ago https://github.com/ocurrent/ocluster/tree/prototype

@RyanGibb
Copy link
Author

Thanks Anil, it looks like Capability.call_for_caps was what I needed!

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