Skip to content
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

Timeout crashes the telnetlib server #51

Closed
zofy opened this issue Jan 25, 2021 · 4 comments
Closed

Timeout crashes the telnetlib server #51

zofy opened this issue Jan 25, 2021 · 4 comments
Labels

Comments

@zofy
Copy link

zofy commented Jan 25, 2021

Hello,
I've encountered a server crash after the timeout occurred. I think the issue was introduced after he circular reference was broken: 782c677

Let's start a simple telnetlib sever with timeout set to 5 seconds.

import asyncio, telnetlib3

@asyncio.coroutine
def shell(reader, writer):
    writer.write('\r\nWould you like to play a game? ')
    inp = yield from reader.read(1)
    if inp:
        writer.echo(inp)
        writer.write('\r\nThey say the only way to win '
                     'is to not play at all.\r\n')
        yield from writer.drain()
    writer.close()


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    coro = telnetlib3.create_server(port=8023, shell=shell, timeout=5)
    server = loop.run_until_complete(coro)
    loop.run_until_complete(server.wait_closed())

After the server is started and client makes a connection (telnet localhost 8023). After 5 seconds, the server crashes with:

Task exception was never retrieved
future: <Task finished name='Task-5' coro=<shell() done, defined at ex.py:3> exception=TypeError("'NoneType' object is not callable")>
Traceback (most recent call last):
  ...
 <home>/.local/lib/python3.8/site-packages/telnetlib3/stream_reader.py", line 125, in decode
    encoding = self.fn_encoding(incoming=True)
TypeError: 'NoneType' object is not callable

Could you verify that this is a bug?
IMHO the TelnetReaderUnicode.read() should be able to take the timeout into account. What do you think?

zofy pushed a commit to zofy/telnetlib3 that referenced this issue Jan 27, 2021
This is a potential fix for the issue jquast#51.
 * BaseServer.connection_lost() notifies the reader that the
connection was lost.
 * TelnetWriter.close() was modified to avoid calling the close, when
it's already closed.
@jquast jquast added the bug label Jan 29, 2021
jquast added a commit that referenced this issue Feb 3, 2021
@jquast
Copy link
Owner

jquast commented Feb 3, 2021

I made 2 additional fixes and merged to master,

  • check fn_encoding is callable in __repr__
  • check for EOF in decode, necessary when read_exactly(1) gets EOF instead

i'll release to pypi in 8 or more hours

@jquast
Copy link
Owner

jquast commented Feb 4, 2021

this fix is going to pypi shortly as 1.0.4

@jquast jquast closed this as completed Feb 4, 2021
@jquast
Copy link
Owner

jquast commented Feb 4, 2021

https://pypi.org/project/telnetlib3/1.0.4/

@zofy
Copy link
Author

zofy commented Feb 4, 2021

Thank you, great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants