@@ -108,7 +108,7 @@ syncFromCodeserver _shouldValidate codeserver branchRef hashJwt = do
108108 -- TODO: proper error handling
109109 Left err -> error $ show err
110110 Right () -> pure ()
111- Debug. debugLogM Debug. Temp " Done sync, flushing temp entities"
111+ Debug. debugLogM Debug. Temp " ! Done sync, flushing temp entities"
112112 causalId <- liftIO $ flushTemp codebase (Share. hashJWTHash hashJwt)
113113 pure $ Right (Sync. hash32ToCausalHash rootCausalHash, causalId)
114114
@@ -129,11 +129,16 @@ doSync codebase SyncState {pendingRequestsVar, yetToRequestVar, toIngestQueue, r
129129 _ <- Ki. fork scope (receiverWorker onErr)
130130 _ <- Ki. fork scope (requesterWorker onErr)
131131 _ <- Ki. fork scope (ingestionWorker onErr)
132+ let finished = do
133+ pending <- readTVar pendingRequestsVar
134+ yetToReq <- readTVar yetToRequestVar
135+ guard $ Set. null pending && Set. null yetToReq
132136
133137 Debug. debugLogM Debug. Temp " Awaiting completion"
134138 result <-
135139 atomically $
136- (Right <$> Ki. awaitAll scope)
140+ (Right <$> finished)
141+ <|> (Right <$> Ki. awaitAll scope)
137142 <|> (Left . Left <$> readTMVar errorVar)
138143 <|> (Left . Right <$> connectionClosed)
139144
@@ -159,6 +164,7 @@ doSync codebase SyncState {pendingRequestsVar, yetToRequestVar, toIngestQueue, r
159164 Debug. debugLogM Debug. Temp " Requester waiting to send requests"
160165 atomically $ do
161166 requests <- readTVar yetToRequestVar
167+ guard $ not (Set. null requests)
162168 writeTVar yetToRequestVar Set. empty
163169 modifyTVar' pendingRequestsVar (Set. union requests)
164170 send $ Msg $ ReceiverEntityRequest $ EntityRequestMsg (Set. toList requests)
@@ -211,11 +217,14 @@ flushTemp codebase rootCausalHash = do
211217 Nothing -> pure ()
212218 Just (hash, tempEntityBytes) ->
213219 do
220+ Debug. debugLogM Debug. Temp $ " Flushing temp entity: " <> show hash
214221 tempEntity <- case CBOR. deserialiseOrFailCBORBytes (CBOR. CBORBytes tempEntityBytes) of
215222 -- TODO: proper error handling
216223 Left err -> error $ show err
217224 Right tempEntity -> pure tempEntity
225+ Debug. debugLogM Debug. Temp $ " Saving in main" <> show hash
218226 void $ Q. saveTempEntityInMain v2HashHandle hash tempEntity
219227 loop
220228 loop
229+ Debug. debugLogM Debug. Temp " Flushed temp entities, getting causal hash id"
221230 Q. expectCausalHashIdByCausalHash (Sync. hash32ToCausalHash rootCausalHash)
0 commit comments