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
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.