Skip to content

Commit

Permalink
Add Timeout to socket.accept(). (#1045)
Browse files Browse the repository at this point in the history
Fixes #1042.
  • Loading branch information
fasaxc committed Jun 24, 2016
1 parent cb2ab8c commit 7dfeb38
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion calico/felix/fetcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ def _start_driver(self):
_log.info("etcd-driver command line: %s", cmd)
self._driver_process = subprocess.Popen(cmd)
_log.info("Started etcd driver with PID %s", self._driver_process.pid)
update_conn, _ = update_socket.accept()
with gevent.Timeout(10):
update_conn, _ = update_socket.accept()
_log.info("Accepted connection on socket")
# No longer need the server socket, remove it.
try:
Expand Down
5 changes: 4 additions & 1 deletion calico/felix/test/test_fetcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,11 @@ def test_on_status_from_driver(self):

@patch("os.path.exists", autospec=True)
@patch("subprocess.Popen")
@patch("gevent.Timeout", autospec=True)
@patch("socket.socket")
@patch("os.unlink")
def test_start_driver(self, m_unlink, m_socket, m_popen, m_exists):
def test_start_driver(self, m_unlink, m_socket, m_timeout, m_popen,
m_exists):
m_exists.return_value = True
m_sck = Mock()
m_socket.return_value = m_sck
Expand All @@ -380,6 +382,7 @@ def test_start_driver(self, m_unlink, m_socket, m_popen, m_exists):
self.assertTrue(isinstance(reader, MessageReader))
self.assertTrue(isinstance(writer, MessageWriter))
m_exists.assert_called_once_with("/run")
m_timeout.assert_called_once_with(10)

@patch("calico.felix.fetcd.sys")
@patch("os.path.exists", autospec=True)
Expand Down

0 comments on commit 7dfeb38

Please sign in to comment.