Commit 7e273ea2 authored by Andrzej Rybczak's avatar Andrzej Rybczak Committed by Ben Gamari
Browse files

Decrease locked region size on Windows to fix ERROR_LOCK_INVALID_RANGE

Reviewers: austin, hvr, bgamari

Subscribers: rwbarton, thomie

Differential Revision:
parent cec90709
......@@ -128,10 +128,10 @@ lockImpl h ctx mode block = do
-- We want to lock the whole file without looking up its size to be
-- consistent with what flock does. According to documentation of LockFileEx
-- "locking a region that goes beyond the current end-of-file position is
-- not an error", however e.g. Windows 10 doesn't accept maximum possible
-- value (a pair of MAXDWORDs) for mysterious reasons. Work around that by
-- leaving the highest bit set to 0.
fix $ \retry -> c_LockFileEx wh flags 0 0xffffffff 0x7fffffff ovrlpd >>= \case
-- not an error", however some versions of Windows seem to have issues with
-- large regions and set ERROR_INVALID_LOCK_RANGE in such case for
-- mysterious reasons. Work around that by setting only low 32 bits.
fix $ \retry -> c_LockFileEx wh flags 0 0xffffffff 0x0 ovrlpd >>= \case
True -> return True
False -> getLastError >>= \err -> if
| not block && err == #{const ERROR_LOCK_VIOLATION} -> return False
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment