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

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

Closed
flensrocker opened this issue Oct 18, 2022 · 4 comments · Fixed by #787

Comments

@flensrocker
Copy link
Contributor

flensrocker commented Oct 18, 2022

Steps to reproduce

This is part of a large WPF application (.NET Framework 4.8), I have to build a small reproduction. I just want to mention this issue in case someone has the same problem.

Expected behavior

TarInputStream.GetNextEntry() should not deadlock when used on the main thread.

Actual behavior

TarInputStream.GetNextEntry() blocks when called on the main thread of an WPF application. In the PR #746 for the async streams I see a lot of .GetAwaiter().GetResult(). This is not a recommended practice, see https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md#warning-deadlocks

Version of SharpZipLib

1.4.0

Obtained from (only keep the relevant lines)

  • Package installed using NuGet
@flensrocker flensrocker changed the title Regression 1.3.3 => 1.4.0: Deadlock when using TarInputStream.Files() in WPF application Regression 1.3.3 => 1.4.0: Deadlock when using TarInputStream.GetNextEntry() in WPF application Oct 18, 2022
@flensrocker
Copy link
Contributor Author

It happens when I wrap the TarInputStream with an GZipStream.

See this small reproduction sample: https://github.com/flensrocker/SharpZipLibDeadLock

When I downgrade SharpZipLib to 1.3.3 it won't lock.

@piksel
Copy link
Member

piksel commented Oct 19, 2022

Thanks for a thorough report! I will investigate this further...

@flensrocker
Copy link
Contributor Author

I took a look at TarInputStream and TarBuffer, but I don't have a good idea how one can separate the sync and async parts (after all, it's "just" the Read* methods which are async), so both sync & async can be provided, without copying the code surrounding the async calls.

I will think about it from time to time and will report any progress if I come up with something.

@flensrocker
Copy link
Contributor Author

Adding .ConfigureAwait(false) to every await seems to fix my issue.

After all it's a "best practice" for general purpose libraries, see https://devblogs.microsoft.com/dotnet/configureawait-faq/

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 a pull request may close this issue.

2 participants