Patchwork [stable] httppeer: make __del__ access to self.urlopener more safe

login
register
mail settings
Submitter Mads Kiilerich
Date Oct. 31, 2016, 12:44 p.m.
Message ID <13b1ef724b8c5c22f923.1477917853@madski>
Download mbox | patch
Permalink /patch/17230/
State Accepted
Headers show

Comments

Mads Kiilerich - Oct. 31, 2016, 12:44 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1477917828 -3600
#      Mon Oct 31 13:43:48 2016 +0100
# Branch stable
# Node ID 13b1ef724b8c5c22f9234f62b9d9a583655ce87e
# Parent  69ffbbe73dd03df0d1a00bdb2bc083fdb73ede09
httppeer: make __del__ access to self.urlopener more safe

Some errors could in some cases show unfortunate scary and confusing warnings
from the httppeer delstructors:

  abort: nodename nor servname provided, or not known
  Exception AttributeError: "'httpspeer' object has no attribute 'urlopener'" in <bound method httpspeer.__del__ of <mercurial.httppeer.httpspeer object at 0x106e1f5d0>> ignored```

To mute that, take 7b15dd9125b3 to the next level and use getattr in __del__.
Yuya Nishihara - Oct. 31, 2016, 1:44 p.m.
On Mon, 31 Oct 2016 13:44:13 +0100, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1477917828 -3600
> #      Mon Oct 31 13:43:48 2016 +0100
> # Branch stable
> # Node ID 13b1ef724b8c5c22f9234f62b9d9a583655ce87e
> # Parent  69ffbbe73dd03df0d1a00bdb2bc083fdb73ede09
> httppeer: make __del__ access to self.urlopener more safe

Looks good. httppeer.__init__() could be skipped entirely.
Queued, thanks.

Patch

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -63,8 +63,9 @@  class httppeer(wireproto.wirepeer):
         self.requestbuilder = urlreq.request
 
     def __del__(self):
-        if self.urlopener:
-            for h in self.urlopener.handlers:
+        urlopener = getattr(self, 'urlopener', None)
+        if urlopener:
+            for h in urlopener.handlers:
                 h.close()
                 getattr(h, "close_all", lambda : None)()