Skip to content

Commit 24ec502

Browse files
author
Alexandre Vincent
committed
[change] Adjust exec_command timeout logic to not wait the double amount
1 parent f2c76e7 commit 24ec502

File tree

1 file changed

+5
-1
lines changed
  • openwisp_controller/connection/connectors

1 file changed

+5
-1
lines changed

openwisp_controller/connection/connectors/ssh.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import socket
3+
import time
34
from io import BytesIO, StringIO
45

56
import paramiko
@@ -186,6 +187,7 @@ def exec_command(
186187
logger.info("Executing command: {0}".format(command))
187188
# execute commmand
188189
try:
190+
start_cmd = time.perf_counter()
189191
stdin, stdout, stderr = self.shell.exec_command(command, timeout=timeout)
190192
# re-raise socket.timeout to avoid being catched
191193
# by the subsequent `except Exception as e` block
@@ -199,7 +201,9 @@ def exec_command(
199201
# workaround https://github.com/paramiko/paramiko/issues/1815
200202
# workaround https://github.com/paramiko/paramiko/issues/1787
201203
# Ref. https://docs.paramiko.org/en/stable/api/channel.html#paramiko.channel.Channel.recv_exit_status # noqa
202-
stdout.channel.status_event.wait(timeout=timeout)
204+
stdout.channel.status_event.wait(
205+
timeout=timeout - int(time.perf_counter() - start_cmd)
206+
)
203207
assert stdout.channel.status_event.is_set()
204208
exit_status = stdout.channel.exit_status
205209
# log standard output

0 commit comments

Comments
 (0)