Skip to content

Fix timeout bug on very long command output #687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions plugins/connection/network_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@
HAS_SCP = False
display = Display()

REGEX_MAX_LENGTH = 1024


def ensure_connect(func):
@wraps(func)
Expand Down Expand Up @@ -1092,7 +1094,7 @@ def _handle_prompt(
"Prompts provided: %s" % (to_text(exc), prompts)
)
for index, regex in enumerate(prompts_regex):
match = regex.search(resp)
match = regex.search(resp[-REGEX_MAX_LENGTH:])
if match:
self._matched_cmd_prompt = match.group()
self._log_messages("matched command prompt: %s" % self._matched_cmd_prompt)
Expand Down Expand Up @@ -1132,7 +1134,7 @@ def _sanitize(self, resp, command=None, strip_prompt=True):
def _find_error(self, response):
"""Searches the buffered response for a matching error condition"""
for stderr_regex in self._terminal_stderr_re:
if stderr_regex.search(response):
if stderr_regex.search(response[-REGEX_MAX_LENGTH:]):
self._log_messages(
"matched error regex (terminal_stderr_re) '%s' from response '%s'"
% (stderr_regex.pattern, response)
Expand All @@ -1149,7 +1151,7 @@ def _find_error(self, response):
def _find_prompt(self, response):
"""Searches the buffered response for a matching command prompt"""
for stdout_regex in self._terminal_stdout_re:
match = stdout_regex.search(response)
match = stdout_regex.search(response[-REGEX_MAX_LENGTH:])
if match:
self._matched_pattern = stdout_regex.pattern
self._matched_prompt = match.group()
Expand Down