Patchwork [STABLE] posix: make poll() restart on interruption by signal (issue5452)

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 22, 2016, 3:03 p.m.
Message ID <31a595985ae3fe122a72.1482419000@mimosa>
Download mbox | patch
Permalink /patch/18007/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 22, 2016, 3:03 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1482416053 -32400
#      Thu Dec 22 23:14:13 2016 +0900
# Branch stable
# Node ID 31a595985ae3fe122a72f597e6af714f11cbd017
# Parent  1914db1b7d9e53c1ab9cf8587758eb66d218fd5c
posix: make poll() restart on interruption by signal (issue5452)

select() is a notable example of syscalls which may fail with EINTR. If we
had a SIGWINCH handler installed, ssh would crash when the terminal window
was resized. This patch fixes the problem.
Gregory Szorc - Dec. 22, 2016, 9:22 p.m.
> On Dec 22, 2016, at 07:03, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1482416053 -32400
> #      Thu Dec 22 23:14:13 2016 +0900
> # Branch stable
> # Node ID 31a595985ae3fe122a72f597e6af714f11cbd017
> # Parent  1914db1b7d9e53c1ab9cf8587758eb66d218fd5c
> posix: make poll() restart on interruption by signal (issue5452)

LGTM.

I wonder if this pattern of retrying due to EINTR warrants a context manager or other helper. But that would be for a separate patch against the default branch.

> 
> select() is a notable example of syscalls which may fail with EINTR. If we
> had a SIGWINCH handler installed, ssh would crash when the terminal window
> was resized. This patch fixes the problem.
> 
> diff --git a/mercurial/posix.py b/mercurial/posix.py
> --- a/mercurial/posix.py
> +++ b/mercurial/posix.py
> @@ -570,7 +570,14 @@ def poll(fds):
> 
>     In unsupported cases, it will raise a NotImplementedError"""
>     try:
> -        res = select.select(fds, fds, fds)
> +        while True:
> +            try:
> +                res = select.select(fds, fds, fds)
> +                break
> +            except select.error as inst:
> +                if inst.args[0] == errno.EINTR:
> +                    continue
> +                raise
>     except ValueError: # out of range file descriptor
>         raise NotImplementedError()
>     return sorted(list(set(sum(res, []))))
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Pierre-Yves David - Dec. 23, 2016, 4 a.m.
On 12/22/2016 10:22 PM, Gregory Szorc wrote:
>
>
>> On Dec 22, 2016, at 07:03, Yuya Nishihara <yuya@tcha.org> wrote:
>>
>> # HG changeset patch
>> # User Yuya Nishihara <yuya@tcha.org>
>> # Date 1482416053 -32400
>> #      Thu Dec 22 23:14:13 2016 +0900
>> # Branch stable
>> # Node ID 31a595985ae3fe122a72f597e6af714f11cbd017
>> # Parent  1914db1b7d9e53c1ab9cf8587758eb66d218fd5c
>> posix: make poll() restart on interruption by signal (issue5452)
>
> LGTM.
>
> I wonder if this pattern of retrying due to EINTR warrants a context manager or other helper. But that would be for a separate patch against the default branch.

That one is pushed, thanks.

Cheers,

Patch

diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -570,7 +570,14 @@  def poll(fds):
 
     In unsupported cases, it will raise a NotImplementedError"""
     try:
-        res = select.select(fds, fds, fds)
+        while True:
+            try:
+                res = select.select(fds, fds, fds)
+                break
+            except select.error as inst:
+                if inst.args[0] == errno.EINTR:
+                    continue
+                raise
     except ValueError: # out of range file descriptor
         raise NotImplementedError()
     return sorted(list(set(sum(res, []))))