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

Event propagation limitations. #580

Open
rruizGit opened this issue Oct 12, 2020 · 0 comments
Open

Event propagation limitations. #580

rruizGit opened this issue Oct 12, 2020 · 0 comments

Comments

@rruizGit
Copy link
Contributor

I'm not sure if this is a bug or an enhancement request. It depends on your view of what an event should be.

Use Case:

  • Using dynamic proxies with events.
  • Use the RemoteRpcTarget functionality and add "two clients".
  • Interface "attached" to exposes an event.

Events Use Case

Nomenclature in the diagram above might not be quite right, but hopefully you can follow. The server JsonRpc added two remote targets. Each of these objects connects to a client. Client #⁠1 publishes a MyAPI object as a local target. Server, Client #⁠2 or Client #⁠3 could retrieve the interface by attaching to the IMyAPI interface.

The IMyAPI interface includes an event that the server or clients can register for.

Problem

The issue here is that three different JsonRpc objects have retrieved dynamic proxies to interact with the MyAPI target. Calling methods from the interface work fine, but events don't work as I expected them. Let's say all three registered for the event. Well, the server JsonRpc will find the event method in a local target and invoke it. Then it is done. The event will not be called in the two clients.

If the server does not register for this event, then DispatchIncomingRequestAsync will look through the remote targets and forward the message. Great, except that it stops after the first one. So only Client #⁠2 will get the event, even if Client #⁠3 is the only one to register for the event, it will never get to it.

Additional Bug

This might be an actual bug. When DispatchIncomingRequestAsync forwards a request when no response is expected, such as a notification.
remoteResponse = await remoteTarget.InvokeCoreAsync(request, null, token).ConfigureAwait(false);
That line retursn a null remoteResponse which causes a JsonRpcError to be returned rather than a "null response".

Our "Fix"

With the caveat that this might not be what the design called for in terms of notifications, we changed our DispatchIncomingRequestAsync so that it forwards notifications to a local target as well as to all remote targets. We also changed it to return a single null result when calling all local and remote targets which seems to be what a notification should return.

	return new JsonRpcResult
	{
	    RequestId = request.RequestId,
	    Result = null,
	};

So in the use case above, everyone would have received the event and Client #⁠1, which raised the notification, receives its single null result. In my mind, that behaves in a more C#ish way.

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

1 participant