[issue14556] telnetlib Telnet.expect fails with timeout=0

Joel Lovinger report at bugs.python.org
Thu Apr 12 05:37:06 CEST 2012


Joel Lovinger <jlovinger at gmail.com> added the comment:

Quick response!

Based on review of Telnet.expect in Python 2.4.3 and Python 2.7.1/2.7.3.  

In Python 2.4.3 the timeout is passed unmodified on each loop iteration to the underlying select to get more data for a potential match. Iteration only ends on EOF, select timeout with no rx, or match. A timeout=0 received data, without blocking, until no more data or a match was found. 

Unfortunately this implementation can extend the timeout indeterminately if the connection consistently has data for each select but no match is made.

Imagine with timeout=10 and a byte coming in every 5 seconds. Select will always succeed and continue to iterate.

Could even happen with timeout=0 if match processing takes long enough for each iteration (high system load, long input buffer, complicated reg ex, etc).

Python 2.7.1 keeps track of overall elapsed time in Telnet.expect itself and explicitly drops out when it exceeds the timeout. Further passes (timeout-elapsed) as the timeout to select.

Works to ensure an expect never exceeds its timeout, but breaks the case where timeout=0 can read non-blocking to find a match.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14556>
_______________________________________


More information about the Python-bugs-list mailing list