Correct mDNS TCP/UDP socket flags
* Explicitly mark TCP and UDP as blocking sockets * Added socket.SO_REUSEADDR to UDP socket * Added socket.SO_REUSEPORT to TCP+UDP sockets * Moved socket creation to inside the worker thread's start() method. * Added a socket.close() to the stop() method. * Enable eventlet patching of the "os" module, required to avoid symptoms which look near identical to [1]. [1]: https://github.com/eventlet/eventlet/issues/210 Closes-Bug: 1444384 Change-Id: Iff642673a33d7b8d2e2c1af833f944330001c33b
This commit is contained in:
parent
ed816e366a
commit
d479133ddb
|
@ -15,7 +15,7 @@
|
|||
# under the License.
|
||||
import eventlet
|
||||
|
||||
eventlet.monkey_patch(os=False)
|
||||
eventlet.monkey_patch()
|
||||
|
||||
import os
|
||||
import socket
|
||||
|
|
|
@ -247,7 +247,9 @@ def bind_tcp(host, port, tcp_backlog):
|
|||
{'host': host, 'port': port})
|
||||
sock_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||
sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
||||
sock_tcp.setblocking(True)
|
||||
sock_tcp.bind((host, port))
|
||||
sock_tcp.listen(tcp_backlog)
|
||||
|
||||
|
@ -259,6 +261,9 @@ def bind_udp(host, port):
|
|||
LOG.info(_LI('Opening UDP Listening Socket on %(host)s:%(port)d') %
|
||||
{'host': host, 'port': port})
|
||||
sock_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock_udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock_udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||
sock_udp.setblocking(True)
|
||||
sock_udp.bind((host, port))
|
||||
|
||||
return sock_udp
|
||||
|
|
|
@ -230,8 +230,12 @@ class DNSService(object):
|
|||
"""
|
||||
DNS Service mixin used by all Designate DNS Services
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DNSService, self).__init__(*args, **kwargs)
|
||||
@abc.abstractproperty
|
||||
def _dns_application(self):
|
||||
pass
|
||||
|
||||
def start(self):
|
||||
super(DNSService, self).start()
|
||||
|
||||
self._dns_sock_tcp = dnsutils.bind_tcp(
|
||||
self._service_config.host,
|
||||
|
@ -242,13 +246,6 @@ class DNSService(object):
|
|||
self._service_config.host,
|
||||
self._service_config.port)
|
||||
|
||||
@abc.abstractproperty
|
||||
def _dns_application(self):
|
||||
pass
|
||||
|
||||
def start(self):
|
||||
super(DNSService, self).start()
|
||||
|
||||
self.tg.add_thread(self._dns_handle_tcp)
|
||||
self.tg.add_thread(self._dns_handle_udp)
|
||||
|
||||
|
@ -260,6 +257,12 @@ class DNSService(object):
|
|||
# _handle_udp are stopped too.
|
||||
super(DNSService, self).stop()
|
||||
|
||||
if hasattr(self, '_dns_sock_tcp'):
|
||||
self._dns_sock_tcp.close()
|
||||
|
||||
if hasattr(self, '_dns_sock_udp'):
|
||||
self._dns_sock_udp.close()
|
||||
|
||||
def _dns_handle_tcp(self):
|
||||
LOG.info(_LI("_handle_tcp thread started"))
|
||||
|
||||
|
|
Loading…
Reference in New Issue