# Buggy code
def start(self):
    if not self.use_upnp:
        self.external_ip = CS.get_external_ip()
        return
    success = False
    yield self._maintain_redirects()
    if self.upnp:
        if not self.upnp_redirects:
            log.error(
                "failed to setup upnp, debugging infomation: %s",
                self.upnp.zipped_debugging_info,
            )
        else:
            success = True
            log.debug(
                "set up upnp port redirects for gateway: %s",
                self.upnp.gateway.manufacturer_string,
            )
    else:
        log.error("failed to setup upnp")
    self.component_manager.analytics_manager.send_upnp_setup_success_fail(
        success, self.get_status()
    )
    self._maintain_redirects_lc.start(360, now=False)


# Traceback (Exception)
2018-10-28 21:39:16,952 WARNING  lbrynet.daemon.Components:712: upnp discovery failed: {http://schemas.microsoft.com/windows/pnpx/2005/11}X_hardwareId
2018-10-28 21:39:16,953 ERROR    lbrynet.daemon.Components:782: failed to setup upnp
Unhandled error in Deferred:
2018-10-28 21:40:32,480 CRITICAL twisted:154: Unhandled error in Deferred:

2018-10-28 21:40:32,481 CRITICAL twisted:154:
Traceback (most recent call last):
File "twisted\internet\defer.py", line 1418, in _inlineCallbacks
File "lbrynet\dht\node.py", line 635, in _iterativeFind
File "twisted\internet\defer.py", line 1362, in returnValue
twisted.internet.defer._DefGen_Return: [<lbrynet.dht.contact._Contact object at 0x067573D0>, <lbrynet.dht.contact._Contact object at 0x06796470>, <lbrynet.dht.contact._Contact object at 0x064A5B30>, <lbrynet.dht.contact._Contact object at 0x067798B0>, <lbrynet.dht.contact._Contact object at 0x06793DB0>, <lbrynet.dht.contact._Contact object at 0x0647D510>, <lbrynet.dht.contact._Contact object at 0x06779890>, <lbrynet.dht.contact._Contact object at 0x06488CF0>]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "twisted\internet\defer.py", line 1416, in _inlineCallbacks
File "twisted\python\failure.py", line 491, in throwExceptionIntoGenerator
File "lbrynet\dht\hashannouncer.py", line 38, in do_store
File "twisted\internet\defer.py", line 1418, in _inlineCallbacks
File "lbrynet\dht\node.py", line 326, in announceHaveBlob
Exception: Cannot determine external IP: None
Unhandled error in Deferred:

# Fixed code
def start(self):
    log.info("detecting external ip")
    if not self.use_upnp:
        self.external_ip = CS.get_external_ip()
        return
    success = False
    yield self._maintain_redirects()
    if self.upnp:
        if not self.upnp_redirects:
            log.error(
                "failed to setup upnp, debugging infomation: %s",
                self.upnp.zipped_debugging_info,
            )
        else:
            success = True
            log.debug(
                "set up upnp port redirects for gateway: %s",
                self.upnp.gateway.manufacturer_string,
            )
    else:
        log.error("failed to setup upnp")
    self.component_manager.analytics_manager.send_upnp_setup_success_fail(
        success, self.get_status()
    )
    self._maintain_redirects_lc.start(360, now=False)