H.Ipc icon indicating copy to clipboard operation
H.Ipc copied to clipboard

Method responses with return types are sent to all connections instead of connection that requested the invoke

Open dberlin opened this issue 4 months ago • 0 comments

Describe the bug

The current source generation will write method responses to all connected connections when initialized on a pipeserver (IE the normal documented way to do it)

This is because of this: https://github.com/HavenDV/H.Ipc/blob/017ef0349183f4c5f40670dedf8e30dbe39c59b0/src/libs/H.Ipc.Generator/SourceGenerationHelper.cs#L213

and

https://github.com/HavenDV/H.Ipc/blob/017ef0349183f4c5f40670dedf8e30dbe39c59b0/src/libs/H.Ipc.Generator/SourceGenerationHelper.cs#L254

While it's hard to tell at a glance in the source generator, connection in both lines is coming from the connection passed to initialize, instead of the connection that is part of the event args. This means the WriteAsync is called on the server, and therefore, writes to all connections. This is more obvious in any generated code, obviously :)

Both lines should be args.Connection.WriteAsync, instead of connection.WriteAsync

Steps to reproduce the bug

Start a server with say a "return a unique id " method. Start say 20 children connecting to it in a loop. Invoke the method from the children. Depending how many children and how fast, you will see multiple children report the same unique id. This is becuase they are receiving a response meant for one of the other children, because the writeasync on the "connection" (really the server) is writing to all connections.

Expected behavior

Only the client that requested an invoke should get the response for that invoke.

Screenshots

No response

NuGet package version

No response

Platform

No response

IDE

No response

Additional context

No response

dberlin avatar Aug 19 '25 16:08 dberlin