microsoft / vs-streamjsonrpc

The StreamJsonRpc library offers JSON-RPC 2.0 over any .NET Stream, WebSocket, or Pipe. With bonus support for request cancellation, client proxy generation, and more.
Other
730 stars 149 forks source link

Allow sending an `[RpcMarshalable]` object *back* to its owner #1064

Closed AArnott closed 1 month ago

AArnott commented 1 month ago

We should make this work instead of fail:

NotSupportedException: Marshaling a proxy back to its owner

The wire protocol was designed to allow this eventually. We should take care to only send it back to its owner and not inadvertently forward it onto another JSON-RPC connection. Here is an illustration of what we propose to add and ensure remains blocked:

sequenceDiagram
    Alice->>+John: [RpcMarshalable] A
    Alice-->>+John: [RpcMarshalable] A
    John-->>-Alice: *new* [RpcMarshalable] A
    John-->>Mike: BLOCK [RpcMarshalable] A

Alice can send John object A. Alice can even send it multiple times and John will see reference equality. But today, John cannot send it "back" to Alice. This is what we intend to enable. John must not be allowed to send the proxy to AA forward to Mike.

AArnott commented 1 month ago

The IMarshalable_MarshaledBackAndForth test is a good place to start since it verifies the limited behavior is in fact limited.