JeffLIrion / adb_shell

A Python implementation of ADB with shell and FileSync functionality.
Apache License 2.0
530 stars 60 forks source link

default_transport_timeout_s is ignored #209

Open le91688 opened 1 year ago

le91688 commented 1 year ago

Description

If you set default transport timeout to 60 seconds, and run a binary that sleeps for 15 seconds, it will throw a tcp timeout error

device = AdbDeviceTcp(ip, int(port), default_transport_timeout_s=60)

Log

  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 842, in shell
    return self._service(b'shell', command.encode('utf8'), transport_timeout_s, read_timeout_s, timeout_s, decode)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 710, in _service
    return b''.join(self._streaming_command(service, command, transport_timeout_s, read_timeout_s, timeout_s)).decode('utf8', _DECODE_ERRORS)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 1290, in _streaming_command
    for data in self._read_until_close(adb_info):
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 1243, in _read_until_close
    cmd, data = self._read_until([constants.CLSE, constants.WRTE], adb_info)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 1213, in _read_until
    cmd, _, _, data = self._io_manager.read(expected_cmds, adb_info, allow_zeros=True)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 339, in read
    cmd, arg0, arg1, data = self._read_packet_from_device(adb_info)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 486, in _read_packet_from_device
    msg = self._read_bytes_from_device(constants.MESSAGE_SIZE, adb_info)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 442, in _read_bytes_from_device
    temp = self._transport.bulk_read(length, adb_info.transport_timeout_s)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/transport/tcp_transport.py", line 120, in bulk_read
    raise TcpTimeoutException(msg)
adb_shell.exceptions.TcpTimeoutException: Reading from 1.2.3.4:1234 timed out (10.0 seconds)
le91688 commented 1 year ago

figured out my issue, but still recommend possibly fixing / consolidating these timeout args in a more intuitive way

the AdbDeviceTcp transport arg was being ignored, and i had to specify read_timeout_s on my device.shell() call

return device.shell(device_dir + binary_file + ECHO_EXIT_CODE, read_timeout_s=60)