aboutsummaryrefslogtreecommitdiff
path: root/Database
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-12-16 13:52:43 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-12-16 13:52:43 -0400
commite63472c258f72656455beaa118d4ba43b615621e (patch)
tree4cd789d3187740a71942efbc4b59ba0ef18ed9d1 /Database
parent9760673f5e76757714f4b7bd185ef41a3d649e7f (diff)
reorder database shutdown to be concurrency safe
If a DbHandle is in use by another thread, it could be queueing changes while shutdown is running. So, wait for the worker to finish before flushing the queue, so that any last-minute writes are included. Before this fix, they would be silently dropped. Of course, if the other thread continues to try to use a DbHandle once it's closed, it will block forever as the worker is no longer reading from the jobs MVar. So, that would crash with "thread blocked indefinitely in an MVar operation".
Diffstat (limited to 'Database')
-rw-r--r--Database/Handle.hs2
1 files changed, 1 insertions, 1 deletions
diff --git a/Database/Handle.hs b/Database/Handle.hs
index 6d312df68..67f759265 100644
--- a/Database/Handle.hs
+++ b/Database/Handle.hs
@@ -142,9 +142,9 @@ queryDb (DbHandle _ jobs _) a = do
closeDb :: DbHandle -> IO ()
closeDb h@(DbHandle worker jobs _) = do
- flushQueueDb h
putMVar jobs CloseJob
wait worker
+ flushQueueDb h
type Size = Int