Fix deadlock in DiscordWebhookSink #1018
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Blazor has a SynchronizationContext because it requires rendering to happen on a single thread.
This becomes a problem if an error occurs in the process of rendering, since we have a sink that synchronously blocks because it can no longer return to the thread which is blocked.
This is a solution to the deadlock, however I am open to discussing it.
The general idea I worked with here was to avoid
async void
as far as possible - which is why I chose to delegate to a separate processor-thread instead.I also played around with the idea of having it retry multiple times, but not sure whether we want that for the 0.0001% of cases where discord presumably is down (I think that's the only case where an unhandled exception would occur here)
Another solution would be to keep the exact same code, but add
ConfigureAwait(false)
for all async calls down the chain but I chose to not do this since we would then be relying on an implementation detail.