Skip to content

Commit

Permalink
Reset self.defer at start rather than on end
Browse files Browse the repository at this point in the history
The discovery phase of an SNMPv3 transaction may cause a timeout to be
generated from the call to snmp_send.  This would cause the loop in
the `TableRetriever.fetchSomeMore()` to exit early, which results
in `self.defer` being reset to `None` before it is returned to the
caller in `TableRetriever.__call__()`.  This results in the caller
not receiving a proper `Deferred` object to attach callbacks to,
while the `SnmpTimeoutError` will be logged as an unhandled exception
in a Deferred by the Twisted reactor.

This patch  resets `self.defer` to a new value at the start of
`__call__()` instead, and never resets it back to `None`, in order for
the caller to always receive a proper Deferred instance.
  • Loading branch information
lunkwill42 committed Nov 15, 2023
1 parent 71d68f3 commit c293172
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pynetsnmp/tableretriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self,
limit=1000):
self.proxy = proxy
self.tableStatus = [_TableStatus(oid) for oid in oids]
self.defer = defer.Deferred()
self.defer = None
if proxy.snmpVersion.find('1') > -1:
self.how = proxy._walk
else:
Expand All @@ -34,6 +34,7 @@ def v2v3how(oids):
self.hit_limit = False

def __call__(self):
self.defer = defer.Deferred()
self.fetchSomeMore()
return self.defer

Expand All @@ -52,7 +53,6 @@ def fetchSomeMore(self):
for ts in self.tableStatus:
results[ts.startOidStr]=dict([(asOidStr(oid), value) for oid, value in ts.result])
self.defer.callback(results)
self.defer = None

def saveResults(self, values, ts):
if values:
Expand All @@ -75,4 +75,4 @@ def saveResults(self, values, ts):

def error(self, why):
self.defer.errback(why)
self.defer = None

0 comments on commit c293172

Please sign in to comment.