reorder database shutdown to be concurrency safe
authorJoey Hess <joeyh@joeyh.name>
Wed, 16 Dec 2015 17:52:43 +0000 (13:52 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 16 Dec 2015 17:52:43 +0000 (13:52 -0400)
commit622da992f894ece03a2f9502c572f8a0d55410de
tree26b76e1f72ff10e9b13ad8bbef10415979231d2d
parent1a051f4300f9ae56e93527485b1aa7cc0fd12332
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".
Database/Handle.hs