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

Don't null out WorkspaceRegistration in Dispose() #49048

Conversation

jasonmalinowski
Copy link
Member

We had a mutable field that was marked as not-nullable, but was nulled out as a part of Dispose(). If a buffer is disconnected from a workspace on a background thread, we raise the event on the background thread which could race with the unsubscribe: we'd null it out, the event fires and then we null ref.

My fix is just to not null this out. There's zero value to nulling this out, and as we see trying to violate safety protections can only cause problems.

@jasonmalinowski jasonmalinowski requested review from a team as code owners October 29, 2020 18:01
@jasonmalinowski jasonmalinowski changed the title Don't null out WorkspaceRegistrations in Dispose() Don't null out WorkspaceRegistration in Dispose() Oct 29, 2020
We had a mutable field that was marked as not-nullable, but was nulled
out as a part of Dispose(). If a buffer is disconnected from a workspace
on a background thread, we raise the event on the background thread
which could race with the unsubscribe: we'd null it out, the event fires
and then we null ref.

My fix is just to not null this out. There's zero value to nulling this
out, and as we see trying to violate safety protections can only cause
problems.
@jasonmalinowski jasonmalinowski force-pushed the fix-null-ref-in-suggestedactionssource branch from 538b7e9 to 62734a4 Compare October 29, 2020 18:03
@sharwell
Copy link
Member

sharwell commented Oct 29, 2020

we raise the event on the background thread

This is not allowed to occur after the call to Dispose(). If there is pending work related to this object, the code that calls Dispose() must wait for this work to complete before calling Dispose().

One of the primary intents of ReferenceCountedDisposable<T> is guarding disposable state that gets used in a concurrent context. The code that makes the callback can take a lease on the disposable state that ensures it will not get released prior to the completion of that callback.

@jasonmalinowski
Copy link
Member Author

jasonmalinowski commented Oct 29, 2020

This is not allowed to occur after the call to Dispose(). If there is pending work related to this object, the code that calls Dispose() must wait for this work to complete before calling Dispose().

In this case, this class is subscribing to an event from an unrelated component. There's no methods being called on the Disposed object.

@jasonmalinowski jasonmalinowski self-assigned this Oct 29, 2020
Base automatically changed from master to main March 3, 2021 23:53
@jasonmalinowski
Copy link
Member Author

This PR was obsoleted by #49051.

@jasonmalinowski jasonmalinowski deleted the fix-null-ref-in-suggestedactionssource branch September 22, 2021 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants