From ceff819d433764c303df42c00b0271084e414e4d Mon Sep 17 00:00:00 2001 From: drebs Date: Mon, 9 Sep 2013 11:13:54 -0300 Subject: Fix events exception raising when ensuring server. Closes #3515. --- changes/bug_3515-events-server-test-fails | 2 ++ src/leap/common/events/server.py | 30 ++++++++---------------------- 2 files changed, 10 insertions(+), 22 deletions(-) create mode 100644 changes/bug_3515-events-server-test-fails diff --git a/changes/bug_3515-events-server-test-fails b/changes/bug_3515-events-server-test-fails new file mode 100644 index 0000000..3b2f99e --- /dev/null +++ b/changes/bug_3515-events-server-test-fails @@ -0,0 +1,2 @@ + o Fix events server exception raising when port is occupied by some other + process. Closes #3515. diff --git a/src/leap/common/events/server.py b/src/leap/common/events/server.py index dc55551..41aede3 100644 --- a/src/leap/common/events/server.py +++ b/src/leap/common/events/server.py @@ -77,34 +77,20 @@ def ensure_server(port=SERVER_PORT): s.connect(('localhost', port)) s.close() # port is taken, check if there's a server running there - ping(port, - reqcbk=lambda req, res: process_ping(port, req, res), - timeout=10) + response = ping(port=port, timeout=1000) + if response is not None and response.status == proto.EventResponse.OK: + logger.info('A server is already running on port %d.', port) + return + # port is taken, and not by an events server + logger.warning( + 'Port %d is taken by something not an events server.', port) + raise PortAlreadyTaken(port) except socket.error: # port is available, run a server logger.info('Launching server on port %d.', port) return EventsServerDaemon.ensure(port) -def process_ping(port, request, response): - """ - Response callback for the ping event. - - :param port: Port that is trying to be used - :type port: int - :param request: Ping request made - :type request: proto.PingRequest - :param response: Response from the event - :type response: proto.EventResponse - """ - if response is not None and response.status == proto.EventResponse.OK: - logger.info('A server is already running on port %d.', port) - return - # port is taken, and not by an events server - logger.warning('Port %d is taken by something not an events server.', port) - raise PortAlreadyTaken(port) - - def ping(port=SERVER_PORT, reqcbk=None, timeout=1000): """ Ping the server. -- cgit v1.2.3 From 9e836e1c38893d726b847f68d2df4143b14ad665 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Fri, 20 Sep 2013 12:09:15 -0300 Subject: Fold in changes. --- CHANGELOG | 4 ++++ changes/bug_3515-events-server-test-fails | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) delete mode 100644 changes/bug_3515-events-server-test-fails diff --git a/CHANGELOG b/CHANGELOG index d39426c..d999d08 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +0.3.3 Sep 20: + o Fix events server exception raising when port is occupied by some + other process. Closes #3515. + 0.3.2 Sep 06: o Use dirspec instead of plain xdg. Closes #3574. o Correct use of CallbackAlreadyRegistered exception. diff --git a/changes/bug_3515-events-server-test-fails b/changes/bug_3515-events-server-test-fails deleted file mode 100644 index 3b2f99e..0000000 --- a/changes/bug_3515-events-server-test-fails +++ /dev/null @@ -1,2 +0,0 @@ - o Fix events server exception raising when port is occupied by some other - process. Closes #3515. -- cgit v1.2.3