kmaragon / Konscious.Security.Cryptography

MIT License
202 stars 20 forks source link

Deadlocks in synchronous GetBytes call #18

Closed sallgeud closed 6 years ago

sallgeud commented 7 years ago

You should consider wrapping this call in an AsyncBridge or investigate the use of ConfigureAwait, etc:

https://blogs.msdn.microsoft.com/pfxteam/2011/01/13/await-and-ui-and-deadlocks-oh-my/

kmaragon commented 6 years ago

There are several issues on this. There is a method available GetBytesAsync that will allow you to use ConfigureAwait to avoid deadlock. It effectively just exposes the same task so it gives you the option to control how you go about handling the synchronization contexts as the consumer of the library.

ilushka85 commented 6 years ago

so while you can definetely use getbytesasync and configureawait to avoid deadlocks... the default synchronus method should not cause deadlocks... we implemented this as a simple function on webapi and it deadlocks 100% of the time with the sync method. Yes we switched to async, but should we have had to ?