# HG changeset patch # User Goffi # Date 1517466274 -3600 # Node ID 78c7992a26ed04d44052191cdc223c14a79e66fb # Parent ed1d71b91b2980a32de855de1f61b907a70bf0dc plugin NAT-port: raise MappingError if something get wrong during "addportmapping" + log unexpected errors (i.e. everything else than MappingError) diff -r ed1d71b91b29 -r 78c7992a26ed src/plugins/plugin_misc_nat-port.py --- a/src/plugins/plugin_misc_nat-port.py Thu Feb 01 07:21:41 2018 +0100 +++ b/src/plugins/plugin_misc_nat-port.py Thu Feb 01 07:24:34 2018 +0100 @@ -150,12 +150,16 @@ # to avoid testing again the first series the next time self._starting_port_cache = ext_port - mapping = self._upnp.addportmapping( - # the last parameter is remoteHost, we don't use it - ext_port, protocol, self._upnp.lanaddr, int_port, desc, '') + try: + mapping = self._upnp.addportmapping( + # the last parameter is remoteHost, we don't use it + ext_port, protocol, self._upnp.lanaddr, int_port, desc, '') + except Exception as e: + log.error(_(u"addportmapping error: {msg}").format(msg=e)) + raise failure.Failure(MappingError()) if not mapping: - raise MappingError + raise failure.Failure(MappingError()) else: self._to_unmap.append((ext_port, protocol)) finally: @@ -182,9 +186,12 @@ ext_port = ext_port, )) return ext_port - def mappingEb(failure): - failure.trap(MappingError) + def mappingEb(failure_): + failure_.trap(MappingError) log.warning(u"Can't map internal {int_port}".format(int_port=int_port)) + def mappingUnknownEb(failure_): + log.error(_(u"error while trying to map ports: {msg}").format(msg=failure_)) d = threads.deferToThread(self._mapPortBlocking, int_port, ext_port, protocol, desc) d.addCallbacks(mappingCb, mappingEb) + d.addErrback(mappingUnknownEb) return d