Skip to content

fix a race in ftp prefetching when using max_concurrent_requests - #2519

Open
davidszotten wants to merge 1 commit into
paramiko:mainfrom
davidszotten:fix-prefetch-race
Open

davidszotten wants to merge 1 commit into
paramiko:mainfrom
davidszotten:fix-prefetch-race

Conversation

@davidszotten

Copy link
Copy Markdown

when max_concurrent_requests is set, it's possible to empty the list of prefetch extents by reading faster than they are enqueued. currently this makes us mistakenly thing the prefetching is all done. reading still works, but it starts ignoring the prefetch which, in particular, means that in the common case of reading an entire file, the prefetch buffers continue filling but are never emptied causing excessive memory use.

fix this by explicitly keeping track of when we're done enqueueing.

when `max_concurrent_requests` is set, it's possible to empty the list
of prefetch extents by reading faster than they are enqueued. currently
this makes us mistakenly thing the prefetching is all done. reading
still works, but it starts ignoring the prefetch which, in particular,
means that in the common case of reading an entire file, the prefetch
buffers continue filling but are never emptied causing excessive memory
use.

fix this by explicitly keeping track of when we're done enqueueing.
@davidszotten

Copy link
Copy Markdown
Author

it looks like the original implementation was by @kschoelhorn and @bwinston-sdp . does this look like the correct diagnosis and reasonable fix to you?

@ddelange

ddelange commented Jun 23, 2025 •

Copy link
Copy Markdown

does this mean we can pass max_concurrent_requests to control network i/o AND bufsize to control RAM usage (i.e. to pause prefetching when the buffer is full)?

@bwinston-sdp

Copy link
Copy Markdown
Contributor

nice find @davidszotten! this seems like the correct diagnosis to me, but I will defer to @bitprophet and/or other maintainers with a better mental model of the prefetch code.

@klemens klemens left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! I somehow didn't notice this when doing #2058. (@kschoelhorn is my work account).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants