fix deadlock in restagePointerFiles
authorJoey Hess <joeyh@joeyh.name>
Thu, 8 Dec 2022 18:18:54 +0000 (14:18 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 8 Dec 2022 18:36:11 +0000 (14:36 -0400)
commit65f9e7a3c73626f17f6f49d0c8266041fd333e93
tree0096c0cf9cfd155914ccf517a59d56f6f640c600
parenta7554f1a6a7e375d39eb56b454a47a7eea75005a
fix deadlock in restagePointerFiles

Fix a hang that occasionally occurred during commands such as move.
(A bug introduced in 10.20220927, in
commit 6a3bd283b8af53f810982e002e435c0d7c040c59)

The restage.log was kept locked while running a complex index refresh
action. In an unusual situation, that action could need to write to the
restage log, which caused a deadlock.

The solution is a two-stage process. First the restage.log is moved to a
work file, which is done with the lock held. Then the content of the work
file is read and processed, which happens without the lock being held.
This is all done in a crash-safe manner.

Note that streamRestageLog may not be fully safe to run concurrently
with itself. That's ok, because restagePointerFiles uses it with the
index lock held, so only one can be run at a time.

streamRestageLog does delete the restage.old file at the end without
locking. If a calcRestageLog is run concurrently, it will either see the
file content before it was deleted, or will see it's missing. Either is
ok, because at most this will cause calcRestageLog to report more
work remains to be done than there is.

Sponsored-by: Dartmouth College's Datalad project
Annex/Locations.hs
CHANGELOG
Logs/File.hs
Logs/Restage.hs
doc/bugs/git_annex_test_never_exits__63__/comment_9_230038504d75704baacd4d3ac750ee95._comment [new file with mode: 0644]