Repository navigation
Stop the SFTP prefetch thread when its file is closed - #2719
Open
CAOShurong wants to merge 1 commit into
Open
CAOShurong wants to merge 1 commit into
CAOShurong wants to merge 1 commit into
Conversation
A limited prefetch kept issuing reads after close(), which raised OSError once the channel was gone or slept forever when a failed read left the in-flight count stuck. close() now joins that thread before CMD_CLOSE. Skip non-POSIX locale tests individually so importing the SFTP module can finish on current pytest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closing an SFTP file left a limited prefetch thread running. After
close(), the thread kept sendingCMD_READ. Closing the client then raisedOSError: Socket is closed. When a later read failed,_async_responseleft that request in_prefetch_extents, the in-flight count stayed at the limit, and the thread slept until the process exited.close()now joins the prefetch threads after the file is marked closed and beforeCMD_CLOSE. The thread returns from its wait loop once it sees the closed file, so it does not start another read. A request already inside_async_requestis still sent;close()waits for that call to return. Requests already on the wire are left for the transport to finish._prefetch_doneis unchanged. A fast reader can still empty the in-flight map before every chunk is queued, which is the race in #2519.requireNonAsciiLocale()calledpytest.skip()while the SFTP tests were imported. On a non-POSIX host that aborts collection of the whole module. Those locale tests are now skipped on their own.inv teston Python 3.13.1 Windows: 366 passed, 13 skipped, 1 failed. The failure istest_new_keyfiles_avoid_descriptor_race_integration: the new key file's mode is0o666rather than0o600.inv test --include-slow -k TestSFTP: 32 passed, 4 skipped, 3 failed (testa_posix_rename,test_symlink,test_chdir).test_prefetch_stops_when_file_closespassed. Those three failures are path and extension behavior in the in-process server on Windows.Fixes #2717.