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 every await #787

Merged
merged 1 commit into from Oct 20, 2022

Conversation

flensrocker
Copy link
Contributor

See https://devblogs.microsoft.com/dotnet/configureawait-faq/

General purpose libraries should always use .CongfigureAwait(false) to avoid deadlocks. It may not prevent from every deadlock but is after all a "best practice".

I also added a .globalconfig to warn if ConfigureAwait calls are missing in future changes.

Fixes #786

I certify that I own, and have sufficient rights to contribute, all source code and related material intended to be compiled or integrated with the source code for the SharpZipLib open source product (the "Contribution"). My Contribution is licensed under the MIT License.

@codecov
Copy link

codecov bot commented Oct 20, 2022

Codecov Report

Merging #787 (c4fd3e2) into master (d2a0c68) will not change coverage.
The diff coverage is 73.23%.

@@           Coverage Diff           @@
##           master     #787   +/-   ##
=======================================
  Coverage   74.70%   74.70%           
=======================================
  Files          72       72           
  Lines        8465     8465           
=======================================
  Hits         6324     6324           
  Misses       2141     2141           
Impacted Files Coverage Δ
src/ICSharpCode.SharpZipLib/Zip/ZipFormat.cs 89.54% <42.85%> (ø)
src/ICSharpCode.SharpZipLib/Tar/TarInputStream.cs 63.20% <52.38%> (ø)
...c/ICSharpCode.SharpZipLib/GZip/GzipOutputStream.cs 86.48% <66.66%> (ø)
src/ICSharpCode.SharpZipLib/Tar/TarOutputStream.cs 67.83% <75.00%> (ø)
src/ICSharpCode.SharpZipLib/Core/ByteOrderUtils.cs 100.00% <100.00%> (ø)
src/ICSharpCode.SharpZipLib/Core/StreamUtils.cs 46.00% <100.00%> (ø)
src/ICSharpCode.SharpZipLib/Tar/TarBuffer.cs 73.12% <100.00%> (ø)
...ib/Zip/Compression/Streams/DeflaterOutputStream.cs 82.47% <100.00%> (ø)
src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs 87.82% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@piksel
Copy link
Member

piksel commented Oct 20, 2022

This is absolutely better overall, but it does only cover up the real bug. The "point" of the TarInputStream async implementation is that it's supposed to run entirely sync when being called with isAsync = false ("This async method lacks ‘await’ operators and will run synchronously").

This should mean that a deadlock would never occur.

Adding the ConfigureAwait(false) to all the await calls will increase the performance though, and is a great catch (far too long since I did async library code, I had actually forgot about it), but it will only bypass the bug here by using another thread.

I will keep the Fixes/auto-close though and create a new issue for it, and get this released ASAP.

@piksel piksel merged commit 6c96ce2 into icsharpcode:master Oct 20, 2022
@flensrocker
Copy link
Contributor Author

If I find time I will take a look at the generated IL (never had that done before) to see, if GetNextEntry will really be sync all the way. I don't know what the compiler does when it comes to SkipToNextEntry etc.. The awaits are a bit nested until it comes to the TarBuffer.ReadRecordAsync where the isAsync is evaluated.

Thank you for merging!

@piksel piksel mentioned this pull request Nov 5, 2022
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.

Regression 1.3.3 => 1.4.0: Deadlock when using TarInputStream.GetNextEntry() in WPF application
2 participants