Endless loop in "_handle_control_chars()" if server sends EOF with zero bytes and endless loop in "channel_authenticate_telnet" in "async_channel.py" with same reason
See original GitHub issueDescribe the bug Bug in asynctelnet. Code never returns from “open()” if server sends EOF. When you connect to telnet server that sends EOFs, your code gets stuck in the endless loop in “_handle_control_chars()”, because asyncio.StreamReader.read(1) will return an empty bytes object if EOF was received and the internal buffer is empty.
Here is a problem lines in “transport.py”: https://github.com/carlmontanari/scrapli/blob/062a5f4995539e2dd3b260c7e1eaf66f19b3bedb/scrapli/transport/plugins/asynctelnet/transport.py#L127-L133
This can be easly fixed with
if not c:
break
after the line number 129,
but there is another problem just right after that one - with authentication in “channel_authenticate_telnet” in “async_channel.py” https://github.com/carlmontanari/scrapli/blob/062a5f4995539e2dd3b260c7e1eaf66f19b3bedb/scrapli/channel/async_channel.py#L329-L339 I see increments in “return_attempts” but there is no limit for them. And it never stops. I think we need to add some variable like “max_auth_return_retry” in “BaseChannelArgs”. And when return_attempts >= max_auth_return_retry - raise ScrapliAuthenticationFailed.
To Reproduce Steps to reproduce the behavior: pip install scrapli==2021.7.30a3
- Your script
conn_dict = {
"host": ip,
"timeout_socket": SCRAPLI_SOCKET_TIMEOUT,
"timeout_transport": SCRAPLI_TRANSPORT_TIMEOUT,
"timeout_ops": SCRAPLI_OPERATION_TIMEOUT,
"comms_prompt_pattern": SCRAPLI_PROMPT_PATTERN,
"port": 23,
"transport": "asynctelnet",
"auth_username": login,
"auth_password": password
}
conn = AsyncGenericDriver(**conn_dict)
try:
await conn.open()
except Exception as ex:
logging.debug(str(ex))
else:
await conn.close()
- What you’re connecting to (vendor, platform, version) D-Link DES-1210-28/ME.
Expected behavior Code returns from “open()” if server sends EOFs with ScrapliAuthenticationFailed.
Screenshots
OS (please complete the following information):
- OS: Windows 10
- scrapli version: 2021.7.30a3
Additional context I need some guidance on how to implement limiting function for “return_attempts” in “channel_authenticate_telnet” in “async_channel.py”.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Cool, will push that up to develop shortly. Thanks for opening this and for the help!!
Carl
I think that
will fix all problems. Tried that with my switch and scrapli works as intended.