Permalink
Browse files

Fix double errbacking, remove inlineCallbacks in the factory

patch by Tristan Seligmann
  • Loading branch information...
1 parent ed864da commit 1791fb02999cfd4d271b93d638898d927f9acbc2 @driftx committed Jun 25, 2010
Showing with 22 additions and 13 deletions.
  1. +13 −12 telephus/protocol.py
  2. +9 −1 test/test_cassandraclient.py
View
@@ -94,7 +94,6 @@ def buildProtocol(self, addr):
def clientGone(self, proto):
self._protos.remove(proto)
- @defer.inlineCallbacks
def submitRequest(self, proto):
def reqError(err, req, d, r):
if isinstance(err, InvalidRequestException) or \
@@ -103,19 +102,21 @@ def reqError(err, req, d, r):
self._pending.remove(d)
else:
self.queue.put((req, d, r))
- return err
def reqSuccess(res, d):
d.callback(res)
self._pending.remove(d)
- request, deferred, retries = yield self.queue.get()
- if not proto in self._protos:
- # may have disconnected while we were waiting for a request
- self.queue.put((request, deferred, retries))
- else:
- d = proto.submitRequest(request)
- retries -= 1
- d.addErrback(reqError, request, deferred, retries)
- d.addCallback(reqSuccess, deferred)
+ def _process((request, deferred, retries)):
+ if not proto in self._protos:
+ # may have disconnected while we were waiting for a request
+ self.queue.put((request, deferred, retries))
+ else:
+ d = proto.submitRequest(request)
+ retries -= 1
+ d.addCallbacks(reqSuccess,
+ reqError,
+ callbackArgs=[deferred],
+ errbackArgs=[request, deferred, retries])
+ return self.queue.get().addCallback(_process)
def pushRequest(self, request, retries=None):
retries = retries or self.request_retries
@@ -131,4 +132,4 @@ def shutdown(self):
p.transport.loseConnection()
for d in self._pending:
if not d.called: d.errback(UserError(string="Shutdown requested"))
-
+
@@ -125,4 +125,12 @@ def test_range_slices(self):
keys = [k.key for k in ks]
for key in ['test', 'test2']:
self.assert_(key in keys)
-
+
+ @defer.inlineCallbacks
+ def test_errback(self):
+ yield self.client.remove('poiqwe', CF)
+ try:
+ yield self.client.get('poiqwe', CF, column='foo')
+ except Exception, e:
+ pass
+

0 comments on commit 1791fb0

Please sign in to comment.