summaryrefslogtreecommitdiffstats
path: root/ipapython/ipautil.py
diff options
context:
space:
mode:
authorTomas Krizek <tkrizek@redhat.com>2016-11-23 13:55:14 +0100
committerMartin Basti <mbasti@redhat.com>2016-12-01 15:20:21 +0100
commitaf0ba661889c2e2c9a35d4cff9681c2abab73649 (patch)
treef5ac0ca4049d0952c9466ff376e5642b11363701 /ipapython/ipautil.py
parent027fc32fe0424659c5aecb4531299fe8d4a503d3 (diff)
downloadfreeipa-af0ba661889c2e2c9a35d4cff9681c2abab73649.tar.gz
freeipa-af0ba661889c2e2c9a35d4cff9681c2abab73649.tar.xz
freeipa-af0ba661889c2e2c9a35d4cff9681c2abab73649.zip
ipa-replica-conncheck: do not close listening ports until required
Previously, a separate thread would be created for each socket used for conncheck. It would also time out after one second, after which it would be closed and reopened again. This caused random failures of conncheck. Now all sockets are handled in a single thread and once the server starts to listen on a port, it does not close that connection until the script finishes. Only IPv6 socket is used for simplicity, since it can handle both IPv6 and IPv4 connections. This requires IPv6 kernel support, which is required by other parts of IPA anyway. https://fedorahosted.org/freeipa/ticket/6487 Reviewed-By: Petr Spacek <pspacek@redhat.com>
Diffstat (limited to 'ipapython/ipautil.py')
-rw-r--r--ipapython/ipautil.py71
1 files changed, 0 insertions, 71 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index 1c95a81f6..f85fa0d1d 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -894,77 +894,6 @@ def host_port_open(host, port, socket_type=socket.SOCK_STREAM, socket_timeout=No
return False
-def bind_port_responder(port, socket_type=socket.SOCK_STREAM, socket_timeout=None, responder_data=None):
- host = None # all available interfaces
- last_socket_error = None
-
- # At first try to create IPv6 socket as it is able to accept both IPv6 and
- # IPv4 connections (when not turned off)
- families = (socket.AF_INET6, socket.AF_INET)
- s = None
-
- for family in families:
- try:
- addr_infos = socket.getaddrinfo(host, port, family, socket_type, 0,
- socket.AI_PASSIVE)
- except socket.error as e:
- last_socket_error = e
- continue
- for res in addr_infos:
- af, socktype, proto, _canonname, sa = res
- try:
- s = socket.socket(af, socktype, proto)
- except socket.error as e:
- last_socket_error = e
- s = None
- continue
-
- if socket_timeout is not None:
- s.settimeout(1)
-
- if af == socket.AF_INET6:
- try:
- # Make sure IPv4 clients can connect to IPv6 socket
- s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
- except socket.error:
- pass
-
- if socket_type == socket.SOCK_STREAM:
- s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-
- try:
- s.bind(sa)
-
- while True:
- if socket_type == socket.SOCK_STREAM:
- s.listen(1)
- connection, _client_address = s.accept()
- try:
- if responder_data:
- connection.sendall(responder_data)
- finally:
- connection.close()
- elif socket_type == socket.SOCK_DGRAM:
- _data, addr = s.recvfrom(1)
-
- if responder_data:
- s.sendto(responder_data, addr)
- except socket.timeout:
- # Timeout is expectable as it was requested by caller, raise
- # the exception back to him
- raise
- except socket.error as e:
- last_socket_error = e
- s.close()
- s = None
- continue
- finally:
- if s:
- s.close()
-
- if s is None and last_socket_error is not None:
- raise last_socket_error # pylint: disable=E0702
-
def reverse_record_exists(ip_address):
"""