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

Make DiagnosticContextCollector thread-safe #10

Merged
merged 4 commits into from
Jun 26, 2019

Conversation

nblumhardt
Copy link
Member

Looking at this again, it would be too easy to violate the single-threadedness of DiagnosticContextCollector in the current design - there's no indication in the API of IDiagnosticContext that there are any constraints on how its called.

This PR introduces a simple mutex to make DiagnosticContextCollector thread-safe. There's a possibility this could be done lock-free, but that's probably fine to punt for a future iteration.

After the PR, the example in #9 (comment) will be correct/safe:

var collector = _diagnosticContext.BeginCollection();
var task = SomeMethodAsync();
collector.TryComplete(...);

@nblumhardt
Copy link
Member Author

Dropping in one more commit that switches Add() for Set() and updates existing values rather than extending the list of collected properties.

@nblumhardt
Copy link
Member Author

Still churning this feature a bit, and keen to get the changes integrated downstream while I have some time available. If everyone will forgive me the indiscretion, I'll merge now recklessly 😁 and push any changes from review feedback in a follow-up PR.

@nblumhardt nblumhardt merged commit 204fe13 into serilog:dev Jun 26, 2019
@nblumhardt nblumhardt mentioned this pull request Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant