Skip to content

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

@RyanGibb

Description

@RyanGibb

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.

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