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

fix: use ConfigureAwait(false) on all awaits #565

Merged
merged 1 commit into from
May 8, 2024

Conversation

gnjack
Copy link
Contributor

@gnjack gnjack commented Apr 24, 2024

Description

Use ConfigureAwait(false) on all awaits. This was already present on some awaits in KafkaFlow, but applied inconsistently.

This allows awaits to continue without forcing the callback to be invoked on the original context or scheduler. This can improve performance and help prevent deadlocks when used in environments with a SynchronizationContext such as ASP .NET Framework or UI applications.

This seems to be best practice in libraries (even if it unfortunately makes async code less simple / clean):

Fixes #563

How Has This Been Tested?

We stopped experiencing stalls in Kafka message consumption in ASP .NET Framework after making this change.

All unit / integration tests pass.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests to cover my changes
  • I have made corresponding changes to the documentation

Disclaimer

By sending us your contributions, you are agreeing that your contribution is made subject to the terms of our Contributor Ownership Statement

@gnjack
Copy link
Contributor Author

gnjack commented Apr 24, 2024

The Roslyn analyzer rule CA2007 can detect this to help prevent new awaits being added without ConfigureAwait(false) but it looks like those aren't enabled - we'd need to explicitly EnableNETAnalyzers in the .NET standard projects.

It also looks like are using Codacy / SonarCube which has rule S3216 to pick this up, but I'm not sure if it'll correctly fire for .NET Standard projects.

@joelfoliveira joelfoliveira merged commit 1bc8d2c into Farfetch:master May 8, 2024
3 checks passed
@gnjack gnjack deleted the fix-configureawait branch May 8, 2024 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[Bug Report]: Consumer worker stalls in ASP .NET Framework
3 participants