microsoft / microsoft/vs-streamjsonrpc
Disposal of marshallable object followed by disposal of jsonRpc on client leads to InvalidOperationException on server
@matteo-prosperi is already working on this.
Since Feb 19, 2025.
- Dominant language
- C#
- Stars
- 937
- Forks
- 178
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 28
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.