Exemplo n.º 1
0
 def _on_discovery_timeout(self):
     if self._done:
         return
     self._done = True
     self.mcast.stopListening()
     self._discovery.errback(
         failure.Failure(defer.TimeoutError('in _on_discovery_timeout')))
Exemplo n.º 2
0
 def OnTimeout(self):
     """On a timeout condition, raise an error"""
     if not self.finished:
         self.finished = 1
         self.result = defer.TimeoutError('SNMP request timed out')
         self.success = 0
     reactor.crash()
Exemplo n.º 3
0
    def _reissue(self, reason, addressesLeft, addressesUsed, query, timeout):
        reason.trap(dns.DNSQueryTimeoutError)

        # If there are no servers left to be tried, adjust the timeout
        # to the next longest timeout period and move all the
        # "used" addresses back to the list of addresses to try.
        if not addressesLeft:
            addressesLeft = addressesUsed
            addressesLeft.reverse()
            addressesUsed = []
            timeout = timeout[1:]

        # If all timeout values have been used this query has failed.  Tell the
        # protocol we're giving up on it and return a terminal timeout failure
        # to our caller.
        if not timeout:
            return failure.Failure(defer.TimeoutError(query))

        # Get an address to try.  Take it out of the list of addresses
        # to try and put it ino the list of already tried addresses.
        address = addressesLeft.pop()
        addressesUsed.append(address)

        # Issue a query to a server.  Use the current timeout.  Add this
        # function as a timeout errback in case another retry is required.
        d = self._query(address, query, timeout[0], reason.value.id)
        d.addErrback(self._reissue, addressesLeft, addressesUsed, query,
                     timeout)
        return d
Exemplo n.º 4
0
 def convert_cancelled(value: failure.Failure):
     # if the original deferred was cancelled, and our timeout has fired, then
     # the reason it was cancelled was due to our timeout. Turn the CancelledError
     # into a TimeoutError.
     if timed_out[0] and value.check(CancelledError):
         raise defer.TimeoutError("Timed out after %gs" % (timeout, ))
     return value
Exemplo n.º 5
0
def _wait(d, timeout=None, running=_wait_is_running):
    from twisted.internet import reactor
    if running:
        raise WaitIsNotReentrantError, REENTRANT_WAIT_ERROR_MSG

    results = []

    def append(any):
        if results is not None:
            results.append(any)

    def crash(ign):
        if results is not None:
            reactor.crash()

    def stop():
        reactor.crash()

    running.append(None)
    try:
        d.addBoth(append)
        if results:
            return results[0]
        d.addBoth(crash)
        if timeout is None:
            timeoutCall = None
        else:
            timeoutCall = reactor.callLater(timeout, reactor.crash)
        reactor.stop = stop
        try:
            reactor.run()
        finally:
            del reactor.stop
        if timeoutCall is not None:
            if timeoutCall.active():
                timeoutCall.cancel()
            else:
                f = failure.Failure(defer.TimeoutError('_wait timed out'))
                return f

        if results:
            return results[0]

        # If the timeout didn't happen, and we didn't get a result or
        # a failure, then the user probably aborted the test, so let's
        # just raise KeyboardInterrupt.

        # FIXME: imagine this:
        # web/test/test_webclient.py:
        # exc = self.assertRaises(error.Error, unittest.wait, method(url))
        #
        # wait() will raise KeyboardInterrupt, and assertRaises will
        # swallow it. Therefore, wait() raising KeyboardInterrupt is
        # insufficient to stop trial. A suggested solution is to have
        # this code set a "stop trial" flag, or otherwise notify trial
        # that it should really try to stop as soon as possible.
        raise KeyboardInterrupt()
    finally:
        results = None
        running.pop()
Exemplo n.º 6
0
	def _timeout(self, key, df, oids, timeout, retryCount):
		try:
			try:
				del self.protocol.requests[ key ]
			except KeyError:
				pass
			if not df.called:
				log.debug( 'timeout check %r', self )
				if retryCount:
					timeout *= 1.5
					retryCount -= 1
					log.debug( 'timeout retry %r %r %r', self, timeout, retryCount )
					request = self.encode(oids, self.community)
					key = self.getRequestKey( request )
					try:
						self.send(request.encode())
					except socket.error, err:
						df.errback( failure.Failure() )
						return
					else:
						timer = reactor.callLater(
							timeout,
							self._timeout, key, df, oids, timeout, retryCount
						)
						self.protocol.requests[key] = df, timer
						return
				log.debug( """timeout raising error: %r""", self )
				df.errback(defer.TimeoutError('SNMP request timed out'))
		except Exception, err:
			df.errback( failure.Failure() )
Exemplo n.º 7
0
 def __init__(self, message, cmdlist, matchFunc=None, timeout=10):
     self.message = message
     self.matchFunc = matchFunc or returner(True)
     self._deferred = defer.Deferred()
     terror = defer.TimeoutError("Message %s response timeout" % message.command)
     self.timeoutCall = reactor.callLater(timeout, self.fail, terror)
     self.cmdlist = cmdlist
Exemplo n.º 8
0
	def tableTimeout( self, df, key, oids, roots, includeStart, retryCount, delay ):
		"""Table timeout implementation

		Table queries timeout if a single retrieval
		takes longer than retryCount * self.timeout
		"""
		if not df.called:
			try:
				if retryCount > 0:
					try:
						if self.proxy.protocol.requests[key][0] is df:
							del self.proxy.protocol.requests[ key ]
					except KeyError:
						pass
					return self.getTable( oids, roots, includeStart, retryCount-1, delay*1.5 )
				try:
					if not self.finished and getattr(self,'df',None):
						self.df.errback( defer.TimeoutError('SNMP request timed out'))
						del self.df
				except defer.AlreadyCalledError:
					pass
			except Exception, err:
				if getattr(self,'df',None) and not self.df.called:
					self.df.errback( err )
					del self.df
				else:
					log.warn(
						"""Unhandled exception %r after request completed, ignoring: %s""",
						log.getException(err),
					)
Exemplo n.º 9
0
 def testFetchFailed(self):
     testMessage = "Testing failed fetches"
     testFailure = failure.Failure(defer.TimeoutError(testMessage))
     self.monitor.checkStartTime = seconds()
     with mock.patch.object(self.monitor, '_resultDown') as mock_resultDown:
         self.monitor._fetchFailed(testFailure)
     mock_resultDown.assert_called_once()
Exemplo n.º 10
0
    def timeoutConnection(self):
        """Called when the connection times out.

        Will fail all pending requests with a TimeoutError.

        """
        self.failRequests(defer.TimeoutError("Connection timeout"))
        self.transport.loseConnection()
Exemplo n.º 11
0
 def test_ignores_timeouts_when_consuming_neighbour_event(self):
     reverseResolve = self.patch(reverse_dns_module, "reverseResolve")
     reverseResolve.return_value = defer.fail(defer.TimeoutError())
     ip = factory.make_ip_address(ipv6=False)
     service = ReverseDNSService()
     yield callWithServiceRunning(service, service.consumeNeighbourEvent,
                                  "create", "%s/32" % ip)
     self.assertThat(reverseResolve, MockCalledOnceWith(ip))
     result = yield deferToDatabase(RDNS.objects.first)
     self.assertThat(result, Is(None))
Exemplo n.º 12
0
    def time_it_out():
        timed_out[0] = True

        try:
            deferred.cancel()
        except:  # noqa: E722, if we throw any exception it'll break time outs
            logger.exception("Canceller failed during timeout")

        if not new_d.called:
            new_d.errback(defer.TimeoutError(timeout, "Deferred"))
Exemplo n.º 13
0
    def _reissue(self, reason, address, query, timeout):
        reason.trap(dns.DNSQueryTimeoutError)

        timeout = timeout[1:]
        if not timeout:
            return failure.Failure(defer.TimeoutError(query))

        d = self._query(address, query, timeout[0], reason.value.id)
        d.addErrback(self._reissue, address, query, timeout)
        return d
Exemplo n.º 14
0
    def timeout(self):
        self.transport.loseConnection()

        # transport cleanup needed for HTTPS connections
        if self.factory.url.startswith(b'https'):
            self.transport.stopProducing()

        self.factory.noPage(
            defer.TimeoutError(f"Getting {self.factory.url} took longer "
                               f"than {self.factory.timeout} seconds."))
Exemplo n.º 15
0
    def timeout(self):
        self.transport.loseConnection()

        # transport cleanup needed for HTTPS connections
        if self.factory.url.startswith(b'https'):
            self.transport.stopProducing()

        self.factory.noPage(\
                defer.TimeoutError("Getting %s took longer than %s seconds." % \
                (self.factory.url, self.factory.timeout)))
Exemplo n.º 16
0
 def _timeout(self, calld, failure, timeout):
     # calld is the deferred returned by __call__.
     self._log.debug(
         "Task timed out  task-id=%s label=%s",
         self.id,
         self.label,
     )
     error = defer.TimeoutError("timeout")
     calld.errback(error)
     self.deferred.errback(error)
     self._ontimeout = None
Exemplo n.º 17
0
    def _doTimeout(self, request):
        """
        Give up the request because of a timeout.

        :param request: The object defining the parameters of the request to
                        issue.
        :type request: twisted.web._newclient.Request
        """
        self._giveUp(
            failure.Failure(
                defer.TimeoutError("Getting %s took longer than %s seconds." %
                                   (request.absoluteURI, self._timeout))))
Exemplo n.º 18
0
        def on_timeout(d):
            e = defer.TimeoutError("(%s) still running at %s secs" % (method.__name__, timeout))
            f = failure.Failure(e)

            try:
                d.errback(f)
            except defer.AlreadyCalledError:
                # if the deferred has been called already but the *back chain
                # is still unfinished, crash the reactor and report timeout
                # error ourself.
                reactor.crash()
                raise
Exemplo n.º 19
0
    def time_it_out():
        timed_out[0] = True

        try:
            deferred.cancel()
        except:  # noqa: E722, if we throw any exception it'll break time outs
            logger.exception("Canceller failed during timeout")

        # the cancel() call should have set off a chain of errbacks which
        # will have errbacked new_d, but in case it hasn't, errback it now.

        if not new_d.called:
            new_d.errback(defer.TimeoutError("Timed out after %gs" % (timeout,)))
Exemplo n.º 20
0
 def _check_and_wait(self, res=None):
     self._check_timeout -= 1
     if self._check_timeout <= 0:
         raise defer.TimeoutError("gave up on command")
     logs = self.collectUpdates()
     if logs.get('stdout') == "this is stdout 0\nthis is stdout 1\n":
         # the emitlogs.py process is now waiting for something to arrive
         # on stdin
         self.cmd.command.pp.transport.write("poke\n")
         return
     if not self.cmd.running:
         self.fail("command finished too early")
     spin = defer.Deferred()
     spin.addCallback(self._check_and_wait)
     reactor.callLater(1, spin.callback, None)
     return spin
Exemplo n.º 21
0
 def substantiate(self, sb):
     if self.substantiated:
         self._clearBuildWaitTimer()
         self._setBuildWaitTimer()
         return defer.succeed(self)
     if self.substantiation_deferred is None:
         if self.parent and not self.missing_timer:
             # start timer.  if timer times out, fail deferred
             self.missing_timer = reactor.callLater(
                 self.missing_timeout, self._substantiation_failed,
                 defer.TimeoutError())
         self.substantiation_deferred = defer.Deferred()
         if self.slave is None:
             self._substantiate()  # start up instance
         # else: we're waiting for an old one to detach.  the _substantiate
         # will be done in ``detached`` below.
     return self.substantiation_deferred
Exemplo n.º 22
0
    def testCheckFailure(self):
        self.monitor.active = True
        with mock.patch.multiple(self.monitor,
                                 getProxyPage=mock.DEFAULT,
                                 _fetchSuccessful=mock.DEFAULT,
                                 _fetchFailed=mock.DEFAULT,
                                 _checkFinished=mock.DEFAULT) as mocks:
            mocks['getProxyPage'].return_value = defer.Deferred()
            self.monitor.check()

        # Check whether the callback works
        testFailure = failure.Failure(defer.TimeoutError("Test failure"))
        self.monitor.getPageDeferred.errback(testFailure)

        mocks['_fetchFailed'].assert_called_once_with(testFailure)
        mocks['_fetchSuccessful'].assert_not_called()
        mocks['_checkFinished'].assert_called()
Exemplo n.º 23
0
 def substantiate(self, sb, build):
     if self.substantiated:
         self._clearBuildWaitTimer()
         self._setBuildWaitTimer()
         return defer.succeed(True)
     if not self._substantiation_notifier:
         if self.parent and not self.missing_timer:
             # start timer.  if timer times out, fail deferred
             self.missing_timer = self.master.reactor.callLater(
                 self.missing_timeout,
                 self._substantiation_failed, defer.TimeoutError())
         self.substantiation_build = build
         if self.conn is None:
             d = self._substantiate(build)  # start up instance
             d.addErrback(log.err, "while substantiating")
         # else: we're waiting for an old one to detach.  the _substantiate
         # will be done in ``detached`` below.
     return self._substantiation_notifier.wait()
Exemplo n.º 24
0
 def onTimeout(d):
     e = defer.TimeoutError("%r (%s) still running at %s secs" %
                            (self, methodName, timeout))
     f = failure.Failure(e)
     # try to errback the deferred that the test returns (for no gorram
     # reason) (see issue1005 and test_errorPropagation in test_deferred)
     try:
         d.errback(f)
     except defer.AlreadyCalledError:
         # if the deferred has been called already but the *back chain is
         # still unfinished, crash the reactor and report timeout error
         # ourself.
         reactor.crash()
         self._timedOut = True  # see self._wait
         todo = self.getTodo()
         if todo is not None and todo.expected(f):
             result.addExpectedFailure(self, f, todo)
         else:
             result.addError(self, f)
Exemplo n.º 25
0
 def substantiate(self, sb, build):
     if self.substantiated:
         self._clearBuildWaitTimer()
         self._setBuildWaitTimer()
         return defer.succeed(True)
     if not self._substantiation_notifier:
         if self.parent and not self.missing_timer:
             # start timer.  if timer times out, fail deferred
             self.missing_timer = self.master.reactor.callLater(
                 self.missing_timeout, self._substantiation_failed,
                 defer.TimeoutError())
         self.substantiation_build = build
         # if substantiate fails synchronously we need to have the deferred ready to be notified
         d = self._substantiation_notifier.wait()
         if self.conn is None:
             self._substantiate(build)
         # else: we're waiting for an old one to detach.  the _substantiate
         # will be done in ``detached`` below.
         return d
     return self._substantiation_notifier.wait()
Exemplo n.º 26
0
 def _timeout(self, reason, query):
     reason.trap(dns.DNSQueryTimeoutError)
     log.msg('Timeout for %r' % query)
     log.msg('Given up')
     return failure.Failure(defer.TimeoutError(query))
Exemplo n.º 27
0
def _cancelled_to_timed_out_error(value, timeout):
    if isinstance(value, failure.Failure):
        value.trap(CancelledError)
        raise defer.TimeoutError(timeout, "Deferred")
    return value
Exemplo n.º 28
0
 def _missing_timer_fired(self):
     self.missing_timer = None
     return self._substantiation_failed(defer.TimeoutError())
Exemplo n.º 29
0
 def do_timeout():
     df.errback(failure.Failure(defer.TimeoutError('in Event.get_deferred')))
     once.unwatch(id1)
     once.unwatch(x)
Exemplo n.º 30
0
 def timeout(self):
     self.transport.loseConnection()
     self.factory.noPage(\
             defer.TimeoutError("Getting %s took longer than %s seconds." % \
             (self.factory.url, self.factory.timeout)))