Skip to content

Commit

Permalink
Fix edge case with parallel reader
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ronf committed Sep 29, 2024
1 parent 125ea08 commit 1f9c8ab
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion asyncssh/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3189,7 +3189,8 @@ async def read(self, size: int = -1,
size = (await self._end()) - offset

try:
if self.read_len and size > self.read_len:
if self.read_len and size > min(self.read_len,
self._handler.max_read_len):
data = await _SFTPFileReader(
self.read_len, self._max_requests, self._handler,
self._handle, offset, size).run()
Expand Down

0 comments on commit 1f9c8ab

Please sign in to comment.