[or-cvs] r18757: {torctl} Fix refcount-related WARNs and bugs and also WARN on traceba (torctl/trunk/python/TorCtl)
mikeperry at seul.org
mikeperry at seul.org
Tue Mar 3 08:39:24 UTC 2009
Author: mikeperry
Date: 2009-03-03 03:39:24 -0500 (Tue, 03 Mar 2009)
New Revision: 18757
Modified:
torctl/trunk/python/TorCtl/PathSupport.py
torctl/trunk/python/TorCtl/StatsSupport.py
torctl/trunk/python/TorCtl/TorCtl.py
Log:
Fix refcount-related WARNs and bugs and also WARN on traceback
seen by Roger instead of crashing.
Modified: torctl/trunk/python/TorCtl/PathSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/PathSupport.py 2009-03-03 06:52:19 UTC (rev 18756)
+++ torctl/trunk/python/TorCtl/PathSupport.py 2009-03-03 08:39:24 UTC (rev 18757)
@@ -826,6 +826,7 @@
ext = self.entry_gen.generate()
for r in path:
r.refcount += 1
+ plog("DEBUG", "Circ refcount "+str(r.refcount)+" for "+r.idhex)
return path
# TODO: Implement example manager.
@@ -1069,6 +1070,10 @@
e = self.consensus.routers[self.exit_id[1:]]
plog("NOTICE", "Requested downed exit "+str(self.exit_id)+" (bw: "+str(e.bw)+", flags: "+str(e.flags)+")")
self.bad_restrictions = True
+ elif self.consensus.routers[self.exit_id[1:]].deleted:
+ e = self.consensus.routers[self.exit_id[1:]]
+ plog("NOTICE", "Requested deleted exit "+str(self.exit_id)+" (bw: "+str(e.bw)+", flags: "+str(e.flags)+", Down: "+str(e.down)+", ref: "+str(e.refcount)+")")
+ self.bad_restrictions = True
else:
self.exit_rstr.add_restriction(IdHexRestriction(self.exit_id))
try:
@@ -1323,15 +1328,20 @@
self.last_exit = None
# Kill this stream
plog("NOTICE", "Closing impossible stream "+str(stream.strm_id)+" ("+str(e)+")")
- self.c.close_stream(stream.strm_id, "4") # END_STREAM_REASON_EXITPOLICY
+ try:
+ self.c.close_stream(stream.strm_id, "4") # END_STREAM_REASON_EXITPOLICY
+ except TorCtl.ErrorReply, e:
+ plog("WARN", "Error closing stream: "+str(e))
return
except TorCtl.ErrorReply, e:
plog("WARN", "Error building circ: "+str(e.args))
self.last_exit = None
# Kill this stream
plog("NOTICE", "Closing stream "+str(stream.strm_id))
- # END_STREAM_REASON_DESTROY
- self.c.close_stream(stream.strm_id, "5")
+ try:
+ self.c.close_stream(stream.strm_id, "5") # END_STREAM_REASON_DESTROY
+ except TorCtl.ErrorReply, e:
+ plog("WARN", "Error closing stream: "+str(e))
return
for u in unattached_streams:
plog("DEBUG",
@@ -1358,6 +1368,7 @@
circ = self.circuits[c.circ_id]
for r in circ.path:
r.refcount -= 1
+ plog("DEBUG", "Close refcount "+str(r.refcount)+" for "+r.idhex)
if r.deleted and r.refcount == 0:
# XXX: This shouldn't happen with StatsRouters..
if r.__class__.__name__ == "StatsRouter":
Modified: torctl/trunk/python/TorCtl/StatsSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/StatsSupport.py 2009-03-03 06:52:19 UTC (rev 18756)
+++ torctl/trunk/python/TorCtl/StatsSupport.py 2009-03-03 08:39:24 UTC (rev 18757)
@@ -196,6 +196,7 @@
# StatsRouters should not be destroyed when Tor forgets about them
# Give them an extra refcount:
self.refcount += 1
+ plog("DEBUG", "Stats refcount "+str(self.refcount)+" for "+self.idhex)
def reset(self):
"Reset all stats on this Router"
Modified: torctl/trunk/python/TorCtl/TorCtl.py
===================================================================
--- torctl/trunk/python/TorCtl/TorCtl.py 2009-03-03 06:52:19 UTC (rev 18756)
+++ torctl/trunk/python/TorCtl/TorCtl.py 2009-03-03 08:39:24 UTC (rev 18757)
@@ -351,9 +351,11 @@
'new' """
if self.idhex != new.idhex:
plog("ERROR", "Update of router "+self.nickname+"changes idhex!")
+ plog("DEBUG", "Updating refcount "+str(self.refcount)+" for "+self.idhex)
for i in new.__dict__.iterkeys():
- if i == "refcount": pass
+ if i == "refcount": continue
self.__dict__[i] = new.__dict__[i]
+ plog("DEBUG", "Updated refcount "+str(self.refcount)+" for "+self.idhex)
def will_exit_to(self, ip, port):
""" Check the entire exitpolicy to see if the router will allow
@@ -1157,6 +1159,10 @@
deleted = filter(lambda r: r.deleted, list)
for d in deleted:
plog("WARN", "Router "+d.idhex+" still present but is deleted. Down: "+str(d.down)+", flags: "+str(d.flags)+", bw: "+str(d.bw))
+
+ zero = filter(lambda r: r.refcount == 0 and r.__class__.__name__ == "StatsRouter", list)
+ for d in zero:
+ plog("WARN", "Router "+d.idhex+" has refcount 0. Del:"+str(d.deleted)+", Down: "+str(d.down)+", flags: "+str(d.flags)+", bw: "+str(d.bw))
def _update_consensus(self, nslist):
self.ns_map = {}
@@ -1202,6 +1208,8 @@
for i in xrange(len(self.sorted_r)): self.sorted_r[i].list_rank = i
plog("DEBUG", "Read " + str(len(d.idlist))+" ND => "
+ str(len(self.sorted_r)) + " routers. Update: "+str(update))
+ # XXX: Verification only. Can be removed.
+ self._sanity_check(self.sorted_r)
return update
def current_consensus(self):
More information about the tor-commits
mailing list