'When datagramReceived raises an exception it is logged but the port
is not disconnected.'

def test_datagramReceivedError(self):

    finalDeferred = defer.Deferred()
    def cbCompleted(ign):
        "\n                                                Flush    the    exceptions    which    the    reactor    should    have    logged    and    make\n                                                sure    they're    actually    there.\n                                                "
        errs = self.flushLoggedErrors(BadClientError)
        self.assertEqual(len(errs), 2, ('Incorrectly    found    %d    errors,    expected    2' % (len(errs),)))
    finalDeferred.addCallback(cbCompleted)
    client = BadClient()
    port = reactor.listenUDP(0, client, interface='127.0.0.1')
    def cbCleanup(result):
        '\n                                                Disconnect    the    port    we    started    and    pass    on    whatever    was    given    to    us\n                                                in    case    it    was    a    Failure.\n                                                '
        return defer.maybeDeferred(port.stopListening).addBoth((lambda ign: result))
    finalDeferred.addBoth(cbCleanup)
    addr = port.getHost()
    attempts = list(range(60))
    succeededAttempts = []
    def makeAttempt():
        "\n                                                Send    one    packet    to    the    listening    BadClient.        Set    up    a    0.1    second\n                                                timeout    to    do    re-transmits    in    case    the    packet    is    dropped.        When    two\n                                                packets    have    been    received    by    the    BadClient,    stop    sending    and    let\n                                                the    finalDeferred's    callbacks    do    some    assertions.\n                                                "
        if (not attempts):
            try:
                self.fail('Not    enough    packets    received')
            except:
                finalDeferred.errback()
        self.failIfIdentical(client.transport, None, 'UDP    Protocol    lost    its    transport')
        packet = intToBytes(attempts.pop(0))
        packetDeferred = defer.Deferred()
        client.setDeferred(packetDeferred)
        client.transport.write(packet, (addr.host, addr.port))
        def cbPacketReceived(packet):
            '\n                                                                A    packet    arrived.        Cancel    the    timeout    for    it,    record    it,    and\n                                                                maybe    finish    the    test.\n                                                                '
            timeoutCall.cancel()
            succeededAttempts.append(packet)
            if (len(succeededAttempts) == 2):
                reactor.callLater(0, finalDeferred.callback, None)
            else:
                makeAttempt()
        def ebPacketTimeout(err):
            "\n                                                                The    packet    wasn't    received    quickly    enough.        Try    sending    another\n                                                                one.        It    doesn't    matter    if    the    packet    for    which    this    was    the\n                                                                timeout    eventually    arrives:    makeAttempt    throws    away    the\n                                                                Deferred    on    which    this    function    is    the    errback,    so    when\n                                                                datagramReceived    callbacks,    so    it    won't    be    on    this    Deferred,    so\n                                                                it    won't    raise    an    AlreadyCalledError.\n                                                                "
            makeAttempt()
        packetDeferred.addCallbacks(cbPacketReceived, ebPacketTimeout)
        packetDeferred.addErrback(finalDeferred.errback)
        timeoutCall = reactor.callLater(0.1, packetDeferred.errback, error.TimeoutError('Timed    out    in    testDatagramReceivedError'))
    makeAttempt()
    return finalDeferred
