Skip to content

Close remote handles after uploads#4

Draft
numbereleven-a wants to merge 1 commit into
wesmar:mainfrom
numbereleven-a:agent/fix-upload-handle-close
Draft

Close remote handles after uploads#4
numbereleven-a wants to merge 1 commit into
wesmar:mainfrom
numbereleven-a:agent/fix-upload-handle-close

Conversation

@numbereleven-a

Copy link
Copy Markdown

Summary

  • Wrap SFTP upload handles and native SCP upload channels with the existing RAII helpers.
  • Close the remote handle before reporting upload completion.
  • Report SFTP close failures as upload write errors.
  • Ensure early-return and interrupted-transfer paths also release the remote handle.

Root cause

SftpUploadFileW stored the SFTP handle and SCP channel in adapter unique_ptrs, but destroying those adapters does not close the underlying libssh2 handle.

As a result, an uploaded file could remain open for writing until the entire SFTP connection was disconnected. On Linux and OpenWrt, attempting to execute that file failed with ETXTBSY:

Text file busy

Verification

Tested against the current upstream main branch on OpenWrt 23.05.5 while keeping the SFTP connection open.

Before:

Text file busy
BEFORE_RC=126
/proc/22338/fd/3 -> /opt/test/sftp_etxtbsy_probe.sh

After:

SFTP_ETXTBSY_PROBE_OK
AFTER_RC=0

No process retained an open file descriptor for the uploaded file after the fixed transfer completed.

The patched upstream source also builds successfully in x64 Release configuration.

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.

1 participant