Bug 26846 - RNGCryptoServiceProvider.GetBytes may hang on unloading application domain
Summary: RNGCryptoServiceProvider.GetBytes may hang on unloading application domain
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib (show other bugs)
Version: 3.12.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-02-08 13:31 UTC by Leonid Shalupov
Modified: 2015-02-08 13:31 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 26846 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Leonid Shalupov 2015-02-08 13:31:42 UTC
We have some code in finalizers that call Guid.NewGuid, which calls RNGCryptoServiceProvider.GetBytes for guid generation.
Sometimes that code hangs on appdomain unload with the following stacktrace from gdb:

#0  0x00007f1b28578dbd in read () at ../sysdeps/unix/syscall-template.S:81
#1  0x00000000005832d9 in read (nbytes=14, buf=0x7f1b271fe382, __fd=0) at /usr/include/x86_64-linux-gnu/bits/unistd.h:44
#2  ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes (handle=0x0, arry=<optimized out>) at rand.c:295
#3  0x0000000041fcb238 in ?? ()
#4  0x00007f1b271fe168 in ?? ()
...

Note that "read" call reads from fd 0 (stdin) which leads to hang.

I found only one case when it's possible:
handle is zeroed in RNGCryptoServiceProvider's destructor
https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Security.Cryptography/RNGCryptoServiceProvider.cs#L145

The following patch was successfully (but not correctly) fixed it: https://github.com/JetBrains/mono/commit/f6d77139e76c4f76ddef954411892367d82795f4

On my codebase the bug is reproduced consistently, but I was unable to extract smaller sample.
I'm ready to test the solution from Mono at any time.