Skip to content

Commit 1f9c8ab

Browse files
committed
Fix edge case with parallel reader
This commit fixes an issue where the parallel I/O mechanism wasn't selected when the application set an explicit block size larger than the requested read size, but also larger than the max read length the server supports, so only a partial result was returned. With this fix, the parallel I/O will always be used when the read size is larger than what the server supports, unless the application sets the block_size to 0 to disable it. In the case where the application block size is larger than the max supported read length on the server, reads will be done with the application-requested block size, but the parallel I/O code will compensate if the returned data is smaller than the requested size. The application can still force a single read call with an arbitrary size by setting block_size to 0, but it will need to deal with a possible partial result.
1 parent 125ea08 commit 1f9c8ab

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

asyncssh/sftp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3189,7 +3189,8 @@ async def read(self, size: int = -1,
31893189
size = (await self._end()) - offset
31903190

31913191
try:
3192-
if self.read_len and size > self.read_len:
3192+
if self.read_len and size > min(self.read_len,
3193+
self._handler.max_read_len):
31933194
data = await _SFTPFileReader(
31943195
self.read_len, self._max_requests, self._handler,
31953196
self._handle, offset, size).run()

0 commit comments

Comments
 (0)