Fix a couple of issues around calling SSHReader.readuntil() with a timeout
This commit fixes a problem where data could be discarded when calling SSHReader.readuntil() or SSHReader.readline() wrapped in a call to asyncio.wait_for() with a timeout. If partial data was received which didn't include the delimiter but the call then timed out, the partial data was previously getting discarded since it was already removed from the buffer. With this change, data remains in the receive buffer until the delimiter is seen. This commit also addresses a race condition where an excception could be raised when issuing a read() immediately after a timeout occurred on a prior read if the new read is executed before the coroutine which issued the previous read had a chance to be scheduled. Now, instead of returning an exception when simultaneous reads are issued, an asyncio lock is used to serialize multiple simultaneous reads on a stream. Order of simultaneous reads is not guaranteed, but each read will wait for others to complete before starting so that the data returned is not interleaved across them. An issue still remains that readuntil() may block indefinitely if the receive window fills up before a delimiter is sent. This will be addressed in a future commit.
R
Ron Frederick committed
8f47a090d00f5d22568dadee65921969a88943f9
Parent: 44578bc