Patchwork D919: zeroconf: do not crash if socket being read is closed by another thread

login
register
mail settings
Submitter phabricator
Date Oct. 4, 2017, 1:16 p.m.
Message ID <f1830f26086db0fbcfe6013f4469a4e1@localhost.localdomain>
Download mbox | patch
Permalink /patch/24463/
State Not Applicable
Headers show

Comments

phabricator - Oct. 4, 2017, 1:16 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG5385b76fd1fd: zeroconf: do not crash if socket being read is closed by another thread (authored by quark, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D919?vs=2374&id=2402

REVISION DETAIL
  https://phab.mercurial-scm.org/D919

AFFECTED FILES
  hgext/zeroconf/Zeroconf.py

CHANGE DETAILS




To: quark, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/hgext/zeroconf/Zeroconf.py b/hgext/zeroconf/Zeroconf.py
--- a/hgext/zeroconf/Zeroconf.py
+++ b/hgext/zeroconf/Zeroconf.py
@@ -80,6 +80,7 @@ 
 __email__ = "paul at scott dash murphy dot com"
 __version__ = "0.12"
 
+import errno
 import itertools
 import select
 import socket
@@ -937,7 +938,16 @@ 
         self.zeroconf.engine.addReader(self, self.zeroconf.socket)
 
     def handle_read(self):
-        data, (addr, port) = self.zeroconf.socket.recvfrom(_MAX_MSG_ABSOLUTE)
+        data = addr = port = None
+        sock = self.zeroconf.socket
+        try:
+            data, (addr, port) = sock.recvfrom(_MAX_MSG_ABSOLUTE)
+        except socket.error as e:
+            if e.errno == errno.EBADF:
+                # some other thread may close the socket
+                return
+            else:
+                raise
         self.data = data
         msg = DNSIncoming(data)
         if msg.isQuery():