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

[Bug]: "InvalidOperationException: Collection was modified" When using joins #787

Closed
rcm-adrien-gervaise opened this issue Dec 7, 2023 · 8 comments
Assignees
Labels

Comments

@rcm-adrien-gervaise
Copy link

Describe the bug 🐞

This is the come-back of #364
Subscribing to a join is still not thread-safe, as GetInitialUpdates will enumerate the underlying Dictionary, which could be updated at the same time.

Step to reproduce

[Fact]
    public void LetsSeeWhetherWeCanRandomlyHitADifferentRaceCondition()
    {
        var leftCache = new SourceCache<Thing, long>(x => x.Id);
        var rightCache = new SourceCache<Thing, long>(x => x.Id);
        var joined = leftCache.Connect().InnerJoin(rightCache.Connect(), x => x.Id,
            (keys, leftThing, rightThing) =>
                new Thing { Id = keys.leftKey, Name = $"{leftThing.Name} x {rightThing.Name}" });

        IDisposable StartUpdating(ISourceCache<Thing, long> sourceCache) =>
            Observable.Range(1, 1000000, Scheduler.Default)
                .Subscribe(x => sourceCache.AddOrUpdate(new Thing { Id = x, Name = $"{x}" }));

        using var leftUpdater = StartUpdating(leftCache);
        using var rightUpdater = StartUpdating(rightCache);
        using var subscription = joined.Subscribe();
    }

Reproduction repository

https://github.com/rcm-adrien-gervaise/DynamicData

Expected behavior

No exception should be thrown

Screenshots 🖼️

No response

IDE

No response

Operating system

No response

Version

No response

Device

No response

DynamicData Version

No response

Additional information ℹ️

Test reproducing the issue and suggested fix on https://github.com/rcm-adrien-gervaise/DynamicData

@JakenVeina
Copy link
Collaborator

Is this coming out of yesterday's release?

@rcm-adrien-gervaise
Copy link
Author

No, this has been around for a while. We have the issue using 7.4.9, but I think it predates that.

@glennawatson
Copy link
Member

No, this has been around for a while. We have the issue using 7.4.9, but I think it predates that.

Just confirming it happens in the brand new release from yesterday?

@JakenVeina
Copy link
Collaborator

Just confirming it happens in the brand new release from yesterday?

Another good question. But probably so, I don't think anything in the release would have affected Join operators.

@RolandPheasant
Copy link
Collaborator

That's a good reproduction thanks:

image

@RolandPheasant
Copy link
Collaborator

This has been fixed and deployed in v 8.3.27

@rcm-adrien-gervaise
Copy link
Author

Thanks for the quick fix !

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants