[commit: ghc] ghc-8.2: Decrease locked region size on Windows to fix ERROR_LOCK_INVALID_RANGE (d18d3d9)

git at git.haskell.org git at git.haskell.org
Wed Mar 15 23:09:02 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-8.2
Link       : http://ghc.haskell.org/trac/ghc/changeset/d18d3d9461cfae0f2926c011fc6c7581d4678bea/ghc

>---------------------------------------------------------------

commit d18d3d9461cfae0f2926c011fc6c7581d4678bea
Author: Andrzej Rybczak <electricityispower at gmail.com>
Date:   Wed Mar 15 14:30:48 2017 -0400

    Decrease locked region size on Windows to fix ERROR_LOCK_INVALID_RANGE
    
    Reviewers: austin, hvr, bgamari
    
    Subscribers: rwbarton, thomie
    
    Differential Revision: https://phabricator.haskell.org/D3345
    
    (cherry picked from commit 7e273ea28fe3630a8fede75ed28f471b7be21b5f)


>---------------------------------------------------------------

d18d3d9461cfae0f2926c011fc6c7581d4678bea
 libraries/base/GHC/IO/Handle/Lock.hsc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libraries/base/GHC/IO/Handle/Lock.hsc b/libraries/base/GHC/IO/Handle/Lock.hsc
index d03e261..5608c18 100644
--- a/libraries/base/GHC/IO/Handle/Lock.hsc
+++ b/libraries/base/GHC/IO/Handle/Lock.hsc
@@ -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



More information about the ghc-commits mailing list