From b47e621749257331788e82e44d1565cf4d32d04b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 30 Apr 2017 13:54:02 -0400 Subject: fix probable race in use of restoreHashes I think there was a race where a SessionKey message had been drained from the TChan, but not yet added to the developer state, which was resonsible for recent instability at startup. It manifested as protocol errors where the prevActivity hash was wrongly Nothing. Fixed by adding a MissingHashes type to tag things whose hashes have been stripped, and adding back the hashes when needed, which always happens inside atomically blocks, so won't have such a race. --- Types.hs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Types.hs') diff --git a/Types.hs b/Types.hs index 78c59a2..7622f6a 100644 --- a/Types.hs +++ b/Types.hs @@ -64,6 +64,10 @@ data Activity a = Activity } deriving (Show, Generic) +-- | Used when a value has had its hashes erased for more efficient +-- transfer over the wire. +data MissingHashes a = MissingHashes a + instance DataSize a => DataSize (Activity a) where dataSize a = dataSize (activity a) + maybe 0 dataSize (prevActivity a) -- cgit v1.2.3