Skip to content

Commit 97366f6

Browse files
committed
Stop timeout should be added to the request timeout
Using the max of the stop timeout and request timeout did not entirely make sure that a stop timeout greater than a request timeout wouldn't fail prematurely with a HTTPTimeout exception. The correct behavior is to add the timeouts together, as the stop timeout is understood to be part of the "request processing time". Any transport-level timeout thus comes in addition to that. Signed-off-by: Maxime Petazzoni <[email protected]>
1 parent 6987326 commit 97366f6

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

docker/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ def stop(self, container, timeout=10):
873873
params = {'t': timeout}
874874
url = self._url("/containers/{0}/stop".format(container))
875875
res = self._post(url, params=params,
876-
timeout=max(timeout, self._timeout))
876+
timeout=(timeout + self._timeout))
877877
self._raise_for_status(res)
878878

879879
def tag(self, image, repository, tag=None, force=False):

tests/test.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -934,27 +934,30 @@ def test_port(self):
934934
)
935935

936936
def test_stop_container(self):
937+
timeout = 2
937938
try:
938-
self.client.stop(fake_api.FAKE_CONTAINER_ID, timeout=2)
939+
self.client.stop(fake_api.FAKE_CONTAINER_ID, timeout=timeout)
939940
except Exception as e:
940941
self.fail('Command should not raise exception: {0}'.format(e))
941942

942943
fake_request.assert_called_with(
943944
url_prefix + 'containers/3cc2351ab11b/stop',
944-
params={'t': 2},
945-
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
945+
params={'t': timeout},
946+
timeout=(docker.client.DEFAULT_TIMEOUT_SECONDS + timeout)
946947
)
947948

948949
def test_stop_container_with_dict_instead_of_id(self):
950+
timeout = 2
949951
try:
950-
self.client.stop({'Id': fake_api.FAKE_CONTAINER_ID}, timeout=2)
952+
self.client.stop({'Id': fake_api.FAKE_CONTAINER_ID},
953+
timeout=timeout)
951954
except Exception as e:
952955
self.fail('Command should not raise exception: {0}'.format(e))
953956

954957
fake_request.assert_called_with(
955958
url_prefix + 'containers/3cc2351ab11b/stop',
956-
params={'t': 2},
957-
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
959+
params={'t': timeout},
960+
timeout=(docker.client.DEFAULT_TIMEOUT_SECONDS + timeout)
958961
)
959962

960963
def test_kill_container(self):

0 commit comments

Comments
 (0)