From 13edeabd929b094ab2ec7288840e62d31d9feb67 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Thu, 5 Jun 2014 11:30:18 +0100 Subject: Fix: force select to wait on timeout Currently the mainloop unintentionally busy-waits if we can't connect to the controller. We want the mainloop's select call to wait for the timeout not for this socket's descriptors (which are always ready). We could just call stop_reading() and stop_writing() but since we won't be needing this socket again we may as well close the entire event source, which calls stop_reading(), stop_writing() and then closes the socket. --- distbuild/connection_machine.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'distbuild') diff --git a/distbuild/connection_machine.py b/distbuild/connection_machine.py index 648ce35a..6dec403f 100644 --- a/distbuild/connection_machine.py +++ b/distbuild/connection_machine.py @@ -118,6 +118,7 @@ class ConnectionMachine(distbuild.StateMachine): logging.error( 'Failed to connect to %s:%s: %s' % (self._addr, self._port, str(e))) + self.mainloop.queue_event(self, ConnectError()) return self._sock_proxy.event_source = None @@ -144,3 +145,5 @@ class ConnectionMachine(distbuild.StateMachine): def _start_timer(self, event_source, event): self._timer.start() + self._sock_proxy.event_source.close() + self._sock_proxy.event_source = None -- cgit v1.2.1