Skip to content

Commit

Permalink
fix(libssh2-runner): fix slow stderr read when no stdout
Browse files Browse the repository at this point in the history
In case there's only stderr stream and no data on stdout, stderr stream
processing waits for stdout processing timeout (0.5s by default). This
causes long processing of many stderr lines as this delay happens for
each line.

Fix by verifying first if given stream has data and proceed to next if
not.

refs: scylladb/java-driver#258
(cherry picked from commit a09dd1e)
  • Loading branch information
soyacz committed Nov 4, 2024
1 parent 661a6c3 commit a6fe0ae
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions sdcm/remote/libssh2_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,25 +440,30 @@ def _process_output( # pylint: disable=too-many-arguments, too-many-branches
if perf_counter() > end_time:
reader.stop()
return False
if stdout_stream is not None:

data_processed = False
if stdout_stream is not None and reader.stdout.qsize():
try:
stdout = reader.stdout.get(timeout=timeout_read_data_chunk)
data = stdout.decode(encoding, errors='ignore') + '\n'
stdout_stream.write(data)
for watcher in watchers:
watcher.submit_line(data)
data_processed = True
except Exception: # pylint: disable=broad-except # noqa: BLE001
pass
if stderr_stream is not None and reader.stderr.qsize():
try:
stderr = reader.stderr.get(timeout=timeout_read_data_chunk)
data = stderr.decode(encoding) + '\n'
stderr_stream.write(data)
for watcher in watchers:
watcher.submit_line(data)
data_processed = True
except Exception: # pylint: disable=broad-except # noqa: BLE001
pass
if stderr_stream is not None:
if reader.stderr.qsize():
try:
stderr = reader.stderr.get(timeout=timeout_read_data_chunk)
data = stderr.decode(encoding) + '\n'
stderr_stream.write(data)
for watcher in watchers:
watcher.submit_line(data)
except Exception: # pylint: disable=broad-except # noqa: BLE001
pass
if not data_processed: # prevent unbounded loop in case no data on the streams
sleep(timeout_read_data_chunk or 0.5)
return True

@staticmethod
Expand Down

0 comments on commit a6fe0ae

Please sign in to comment.