[Mono-dev] Data protection failed exception
Edward Ned Harvey (mono)
edward.harvey.mono at clevertrove.com
Fri Jan 22 12:05:45 UTC 2016
> From: mono-devel-list-bounces at lists.ximian.com [mailto:mono-devel-list-
> bounces at lists.ximian.com] On Behalf Of Neale Ferguson
> Further to the problem, tt seems to be a threading issue since if a lock
> is put around this method call:
> return ProtectedData.Protect(data, extraEntropy, dataProtectionScope);
> then it would work. This seems to try an access some file in .mono/keypair
> and it seems to be some concurrency issue since we have multiple threads
> all calling this code at the same time and that’s where it get tripped up.
It sounds like you've nailed it. ProtectedData indeed accesses key files in ~/.config/.mono/keypairs (slightly different from what you said) and if you've got multiple threads accessing that concurrently, locking or sharing will be necessary. Evidently, that's not working, so it should be a relatively straightforward thing to test (or find in source) if mono is / isn't supporting locking / sharing for those operations.
Given that you wrapping ProtectedData in a lock() solves the problem, most likely this is a mono bug, in which ProtectedData is not threadsafe. Your workaround will be to continue using the lock.
More information about the Mono-devel-list