From 1f9c8abeaaf32abb0c3c1aa36924245d2402e984 Mon Sep 17 00:00:00 2001 From: Ron Frederick Date: Sat, 28 Sep 2024 17:47:02 -0700 Subject: [PATCH] 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. --- asyncssh/sftp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/asyncssh/sftp.py b/asyncssh/sftp.py index 48bb9c9..50b7bfa 100644 --- a/asyncssh/sftp.py +++ b/asyncssh/sftp.py @@ -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()