Patchwork [stable] lock: handle race in trylock/testlock on Windows

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 2, 2013, 12:59 p.m.
Message ID <964b123c4831abac69ef.1380718768@gimlet>
Download mbox | patch
Permalink /patch/2692/
State Accepted
Commit 76c83107a724ce6069098075427575f665f01a7f
Headers show

Comments

Yuya Nishihara - Oct. 2, 2013, 12:59 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1380716200 -32400
#      Wed Oct 02 21:16:40 2013 +0900
# Branch stable
# Node ID 964b123c4831abac69efc5a089c446222915713f
# Parent  4d513f96a565639c0879086b68cf72a1e01e596c
lock: handle race in trylock/testlock on Windows

readlock may raise IOError if the system does not support symlink.
Nikolaj Sjujskij - Oct. 2, 2013, 2:11 p.m.
On Wed, 02 Oct 2013 16:59:28 +0400, Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1380716200 -32400
> #      Wed Oct 02 21:16:40 2013 +0900
> # Branch stable
> # Node ID 964b123c4831abac69efc5a089c446222915713f
> # Parent  4d513f96a565639c0879086b68cf72a1e01e596c
> lock: handle race in trylock/testlock on Windows
>
> readlock may raise IOError if the system does not support symlink.
>
> diff --git a/mercurial/lock.py b/mercurial/lock.py
> --- a/mercurial/lock.py
> +++ b/mercurial/lock.py
> @@ -100,7 +100,7 @@ class lock(object):
>          """
>          try:
>              locker = util.readlock(self.f)
> -        except OSError, why:
> +        except (OSError, IOError), why:
>              if why.errno == errno.ENOENT:
>                  return None
>              raise

  Could IOError.errno == errno.ENOENT? Otherwise this change doesn't seem  
to really change anything.
Yuya Nishihara - Oct. 2, 2013, 2:33 p.m.
On Wed, 02 Oct 2013 18:11:09 +0400, Nikolaj Sjujskij wrote:
> On Wed, 02 Oct 2013 16:59:28 +0400, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> > # HG changeset patch
> > # User Yuya Nishihara <yuya@tcha.org>
> > # Date 1380716200 -32400
> > #      Wed Oct 02 21:16:40 2013 +0900
> > # Branch stable
> > # Node ID 964b123c4831abac69efc5a089c446222915713f
> > # Parent  4d513f96a565639c0879086b68cf72a1e01e596c
> > lock: handle race in trylock/testlock on Windows
> >
> > readlock may raise IOError if the system does not support symlink.
> >
> > diff --git a/mercurial/lock.py b/mercurial/lock.py
> > --- a/mercurial/lock.py
> > +++ b/mercurial/lock.py
> > @@ -100,7 +100,7 @@ class lock(object):
> >          """
> >          try:
> >              locker = util.readlock(self.f)
> > -        except OSError, why:
> > +        except (OSError, IOError), why:
> >              if why.errno == errno.ENOENT:
> >                  return None
> >              raise
> 
>   Could IOError.errno == errno.ENOENT? Otherwise this change doesn't seem  
> to really change anything.

Yes.  I've confirmed the problem on Windows by inserting sleep(1) in trylock.
And if errno isn't ENOENT, the exception must be raised.

Regards,
Matt Mackall - Oct. 20, 2013, 10:37 p.m.
On Wed, 2013-10-02 at 21:59 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1380716200 -32400
> #      Wed Oct 02 21:16:40 2013 +0900
> # Branch stable
> # Node ID 964b123c4831abac69efc5a089c446222915713f
> # Parent  4d513f96a565639c0879086b68cf72a1e01e596c
> lock: handle race in trylock/testlock on Windows

This is queued, thanks.

Patch

diff --git a/mercurial/lock.py b/mercurial/lock.py
--- a/mercurial/lock.py
+++ b/mercurial/lock.py
@@ -100,7 +100,7 @@  class lock(object):
         """
         try:
             locker = util.readlock(self.f)
-        except OSError, why:
+        except (OSError, IOError), why:
             if why.errno == errno.ENOENT:
                 return None
             raise