Skip to content

Copy invocation handler list in Java client #43402

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

Merged
merged 2 commits into from
Aug 19, 2022

Conversation

BrennanConroy
Copy link
Member

No one reported this even though it failed a few times...

Root cause was that we were removing an .on handler from the list while an invocation was currently looping over the list, which of course can cause issues. In our other clients we copy the list whenever we are about to loop over it, so doing the same in the Java client.

@BrennanConroy BrennanConroy added area-signalr Includes: SignalR clients and servers feature-client-java Related to the SignalR Java client labels Aug 19, 2022
Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think copy-on-write would likely be better assuming these lists are read more than they're modified, but this fixes the bug.

lock.lock();
List<InvocationHandler> handlers = this.handlers.get(key);
if (handlers != null) {
handlers.remove(handler);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of mutating the existing list, wouldn't it likely be more efficient to make this copy-on-write and replace the reference so we don't have to copy it every time in get()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that's a good point. Looks like that's what we do in the .NET client so at least we were smart there 😄

@adityamandaleeka
Copy link
Member

Approved for RC1.

@adityamandaleeka adityamandaleeka enabled auto-merge (squash) August 19, 2022 22:19
@adityamandaleeka adityamandaleeka merged commit 76b6868 into release/7.0-rc1 Aug 19, 2022
@adityamandaleeka adityamandaleeka deleted the brecon/fixJavatest branch August 19, 2022 23:14
@BrennanConroy BrennanConroy added this to the 7.0-rc1 milestone Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers feature-client-java Related to the SignalR Java client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants