From: Brian Warner <warner@lothar.com>
Date: Tue, 12 Jan 2010 00:07:23 +0000 (-0800)
Subject: tidy up DeadReferenceError handling, ignore them in add_lease calls
X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/css/flags/?a=commitdiff_plain;h=bacb6fe5aad1f4169ebccadf58c310e9a791aa52;p=tahoe-lafs%2Ftahoe-lafs.git

tidy up DeadReferenceError handling, ignore them in add_lease calls

Stop checking separately for ConnectionDone/ConnectionLost, since those have
been folded into DeadReferenceError since foolscap-0.3.1 . Write
rrefutil.trap_deadref() in terms of rrefutil.trap_and_discard() to improve
code coverage.
---

diff --git a/src/allmydata/immutable/checker.py b/src/allmydata/immutable/checker.py
index b8642c35..cbb8637d 100644
--- a/src/allmydata/immutable/checker.py
+++ b/src/allmydata/immutable/checker.py
@@ -104,6 +104,8 @@ class Checker(log.PrefixingLogMixin):
         # particular we want to log any local errors caused by coding
         # problems.
 
+        if f.check(DeadReferenceError):
+            return
         if f.check(RemoteException):
             if f.value.failure.check(KeyError, IndexError, NameError):
                 # this may ignore a bit too much, but that only hurts us
diff --git a/src/allmydata/mutable/servermap.py b/src/allmydata/mutable/servermap.py
index 716b1b47..ccc586b6 100644
--- a/src/allmydata/mutable/servermap.py
+++ b/src/allmydata/mutable/servermap.py
@@ -756,6 +756,8 @@ class ServermapUpdater:
         # particular we want to log any local errors caused by coding
         # problems.
 
+        if f.check(DeadReferenceError):
+            return
         if f.check(RemoteException):
             if f.value.failure.check(KeyError, IndexError, NameError):
                 # this may ignore a bit too much, but that only hurts us
diff --git a/src/allmydata/stats.py b/src/allmydata/stats.py
index 2ae63dbf..5c1cdb3d 100644
--- a/src/allmydata/stats.py
+++ b/src/allmydata/stats.py
@@ -10,7 +10,6 @@ from twisted.application import service
 from twisted.application.internet import TimerService
 from zope.interface import implements
 from foolscap.api import eventually, DeadReferenceError, Referenceable, Tub
-from twisted.internet.error import ConnectionDone, ConnectionLost
 
 from allmydata.util import log
 from allmydata.interfaces import RIStatsProvider, RIStatsGatherer, IStatsProducer
@@ -218,7 +217,7 @@ class StatsGatherer(Referenceable, service.MultiService):
         # this is called lazily, when a get_stats request fails
         del self.clients[tubid]
         del self.nicknames[tubid]
-        f.trap(DeadReferenceError, ConnectionDone, ConnectionLost)
+        f.trap(DeadReferenceError)
 
     def log_client_error(self, f, tubid):
         log.msg("StatsGatherer: error in get_stats(), peerid=%s" % tubid,
diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py
index f5c5c91e..8988ab3e 100644
--- a/src/allmydata/test/test_system.py
+++ b/src/allmydata/test/test_system.py
@@ -4,7 +4,6 @@ from cStringIO import StringIO
 from twisted.trial import unittest
 from twisted.internet import defer
 from twisted.internet import threads # CLI tests use deferToThread
-from twisted.internet.error import ConnectionDone, ConnectionLost
 import allmydata
 from allmydata import uri
 from allmydata.storage.mutable import MutableShareFile
@@ -262,7 +261,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
                 self.fail("interrupted upload should have failed, not finished"
                           " with result %s" % (res,))
             def _interrupted(f):
-                f.trap(ConnectionLost, ConnectionDone, DeadReferenceError)
+                f.trap(DeadReferenceError)
 
                 # make sure we actually interrupted it before finishing the
                 # file
diff --git a/src/allmydata/util/rrefutil.py b/src/allmydata/util/rrefutil.py
index 8d2d6c2a..fd2259b6 100644
--- a/src/allmydata/util/rrefutil.py
+++ b/src/allmydata/util/rrefutil.py
@@ -22,5 +22,4 @@ def trap_and_discard(f, *errorTypes):
     pass
 
 def trap_deadref(f):
-    f.trap(DeadReferenceError)
-    pass
+    return trap_and_discard(f, DeadReferenceError)