diff options
author | Zac Medico <zmedico@gentoo.org> | 2016-11-13 23:16:51 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2016-11-13 23:23:19 -0800 |
commit | 613bb0efeebe6461b37df6baa862f4a3e67c94c7 (patch) | |
tree | 8646feac27f46f28f4e84573c9f98ebb64714fbf | |
parent | Add missed output mode function assignment. (diff) | |
download | mirrorselect-613bb0efeebe6461b37df6baa862f4a3e67c94c7.tar.gz mirrorselect-613bb0efeebe6461b37df6baa862f4a3e67c94c7.tar.bz2 mirrorselect-613bb0efeebe6461b37df6baa862f4a3e67c94c7.zip |
deeptime: cancel alarm signal before handling socket.error (bug 523312)
In order to avoid a race condition, the alarm signal must be cancelled
before socket.error is handled.
X-Gentoo-Bug: 523312
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=523312
-rw-r--r-- | mirrorselect/selectors.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/mirrorselect/selectors.py b/mirrorselect/selectors.py index 1aa5f11..cf70b21 100644 --- a/mirrorselect/selectors.py +++ b/mirrorselect/selectors.py @@ -300,22 +300,24 @@ class Deep(object): ips = [] for addr_family in self._addr_families: try: - signal.alarm(self._dns_timeout) - for result in socket.getaddrinfo(url_parts.hostname, None, - addr_family, socket.SOCK_STREAM, 0, socket.AI_ADDRCONFIG): - family, _, __, ___, sockaddr = result - ip = sockaddr[0] - if family == socket.AF_INET6: - ip = "[%s]" % ip - ips.append(ip) + try: + signal.alarm(self._dns_timeout) + for result in socket.getaddrinfo( + url_parts.hostname, None, addr_family, + socket.SOCK_STREAM, 0, socket.AI_ADDRCONFIG): + family, _, __, ___, sockaddr = result + ip = sockaddr[0] + if family == socket.AF_INET6: + ip = "[%s]" % ip + ips.append(ip) + finally: + signal.alarm(0) except socket.error as e: self.output.write('deeptime(): dns error for host %s: %s\n' % (url_parts.hostname, e), 2) except TimeoutException: self.output.write('deeptime(): dns timeout for host %s\n' % url_parts.hostname, 2) - finally: - signal.alarm(0) if not ips: self.output.write('deeptime(): unable to resolve ip for host %s\n' |