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

Disposal of marhsallable object followed by disposal of jsonRpc on client leads to InvalidOperationException on server #1087

Open
ni28 opened this issue Oct 24, 2024 · 2 comments
Labels

Comments

@ni28
Copy link

ni28 commented Oct 24, 2024

Sometimes I get the following exception on server side on 'await jsonRpc.Completion' when jsonRpc is disposed just after disposal of marshallable object on client side:

  System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
     at System.Collections.Generic.List`1.Enumerator.MoveNext()
     at StreamJsonRpc.Reflection.RpcTargetInfo.DisposeAsync()
     at StreamJsonRpc.JsonRpc.JsonRpcDisconnectedShutdownAsync(JsonRpcDisconnectedEventArgs eventArgs)

I believe the reason is a race condition when accessing the localTargetObjectsToDispose field in the RpcTargetInfo class from different threads. There are other non-concurrent collections in the RpcTargetInfo that probably also need attention.

I created a stress test to reproduce this (attached). It may take a while to get the exception in the server console.

vs-streamjsonrpc-test.zip

@AArnott AArnott added the bug label Oct 24, 2024
@AArnott
Copy link
Member

AArnott commented Oct 24, 2024

Thank you for your report, investigation and repro! What an awesome bug report.

@AArnott
Copy link
Member

AArnott commented Oct 26, 2024

@matteo-prosperi I wonder if you could take a first look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants