diff options
author | Kiall Mac Innes <kiall@macinnes.ie> | 2015-04-13 14:34:38 +0100 |
---|---|---|
committer | Kiall Mac Innes <kiall@macinnes.ie> | 2015-04-14 07:54:30 +0000 |
commit | c888e0892b97fc0f6604d3893d07ec4e40f2f585 (patch) | |
tree | f0ad3a0fb0601a2983449a2e3787c4ecbe404e64 | |
parent | 542ddc47b645b144212512697a9f91ff70cb5407 (diff) | |
download | designate-c888e0892b97fc0f6604d3893d07ec4e40f2f585.tar.gz |
Ensure mDNS TCP/UDP threads service unhandled exceptions
Change-Id: I304fae07c3b83c48e152ac2e8600ff214d1d8a0f
Closes-Bug: 1443453
-rw-r--r-- | designate/service.py | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/designate/service.py b/designate/service.py index 5dfc3bc1..7816b6d3 100644 --- a/designate/service.py +++ b/designate/service.py @@ -264,18 +264,18 @@ class DNSService(object): LOG.info(_LI("_handle_tcp thread started")) while True: - client, addr = self._dns_sock_tcp.accept() + try: + client, addr = self._dns_sock_tcp.accept() - if self._service_config.tcp_recv_timeout: - client.settimeout(self._service_config.tcp_recv_timeout) + if self._service_config.tcp_recv_timeout: + client.settimeout(self._service_config.tcp_recv_timeout) - LOG.debug("Handling TCP Request from: %(host)s:%(port)d" % - {'host': addr[0], 'port': addr[1]}) + LOG.debug("Handling TCP Request from: %(host)s:%(port)d" % + {'host': addr[0], 'port': addr[1]}) - # Prepare a variable for the payload to be buffered - payload = "" + # Prepare a variable for the payload to be buffered + payload = "" - try: # Receive the first 2 bytes containing the payload length expected_length_raw = client.recv(2) (expected_length, ) = struct.unpack('!H', expected_length_raw) @@ -292,21 +292,41 @@ class DNSService(object): LOG.warn(_LW("TCP Timeout from: %(host)s:%(port)d") % {'host': addr[0], 'port': addr[1]}) - # Dispatch a thread to handle the query - self.tg.add_thread(self._dns_handle, addr, payload, client=client) + except struct.error: + client.close() + LOG.warn(_LW("Invalid packet from: %(host)s:%(port)d") % + {'host': addr[0], 'port': addr[1]}) + + except Exception: + client.close() + LOG.exception(_LE("Unknown exception handling TCP request " + "from: %(host)s:%(port)d") % + {'host': addr[0], 'port': addr[1]}) + + else: + # Dispatch a thread to handle the query + self.tg.add_thread(self._dns_handle, addr, payload, + client=client) def _dns_handle_udp(self): LOG.info(_LI("_handle_udp thread started")) while True: - # TODO(kiall): Determine the appropriate default value for - # UDP recvfrom. - payload, addr = self._dns_sock_udp.recvfrom(8192) + try: + # TODO(kiall): Determine the appropriate default value for + # UDP recvfrom. + payload, addr = self._dns_sock_udp.recvfrom(8192) + + LOG.debug("Handling UDP Request from: %(host)s:%(port)d" % + {'host': addr[0], 'port': addr[1]}) - LOG.debug("Handling UDP Request from: %(host)s:%(port)d" % - {'host': addr[0], 'port': addr[1]}) + # Dispatch a thread to handle the query + self.tg.add_thread(self._dns_handle, addr, payload) - self.tg.add_thread(self._dns_handle, addr, payload) + except Exception: + LOG.exception(_LE("Unknown exception handling UDP request " + "from: %(host)s:%(port)d") % + {'host': addr[0], 'port': addr[1]}) def _dns_handle(self, addr, payload, client=None): """ |