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

Workspace.Windows collection is not accessed/updated atomically #76

Closed
josteink opened this issue Oct 8, 2019 · 2 comments
Closed

Workspace.Windows collection is not accessed/updated atomically #76

josteink opened this issue Oct 8, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@josteink
Copy link
Member

josteink commented Oct 8, 2019

I often get the following exception while running workspacer:

image

We either need to provide locked access on object, or make updates atomic.

We should probably also replace IEnumerable<> with an explicit Array-type or List-type, to be better able to control enumeration and avoid situations like this.

Unless someone else beats me to it, I will probably try to debug this more in depth and find out where the collisions occur, and possibly tighten up the code.

@rickbutton
Copy link
Member

Yep, workspacer does a lot of things non-atomically all over the place, and mutates global state on a bunch of threads.

This is one of the places where the initial design failed to fulfill the requirements of the full application, so things got a little hairy, although it doesn't cause problems usually.

I'm open to suggestions as to how to improve this, short of gutting the entire application in a refactor (not opposed, but would enjoy some direction first).

@josteink
Copy link
Member Author

josteink commented Nov 29, 2019

Ok. So based on the branch I've submitted as "Managed Windows", I've been able to reproduce this error, and I think fixing it is pretty straight forward.

I'll update the PR to include those fixes, and then merging that PR should also close this bug.

So I'm working with Windows, and then VS breaks workspacer into Debug mode:

image

Looking into parallel stacks there are only 2 concurrent stacks working with Windows:

image

What's going on in the first thread is pretty obvious: We're enumerating _windows and it's being modified underneath our feet.

Looking at the other stack, I just went down a few frames until I found this:

image

And currentWorkspace here is the same workspace as the one producing the exception! (Notice it's the same object, with object-id $1).

So basically what we need to do is add the following around the code inside AddWindow(), RemoveWindow() and the ManagedWindows-property:

lock (_windows)
{
   // code
}

And this problem should be history.

Any objections?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants