Skip to content

fix(sftp): fix UI freeze and READDIR hang on directories with special files - #26

Merged
Orinks merged 3 commits into
devfrom
fix/sftp-directory-hang
Mar 1, 2026
Merged

fix(sftp): fix UI freeze and READDIR hang on directories with special files#26
Orinks merged 3 commits into
devfrom
fix/sftp-directory-hang

Conversation

@Orinks

@Orinks Orinks commented Mar 1, 2026

Copy link
Copy Markdown
Owner

Problem

Two related issues caused the app to freeze or hang when navigating remote directories:

  1. UI freeze: Directory listing and chdir were running on the main thread, blocking the entire UI
  2. Infinite READDIR loop: Some SFTP servers (e.g. Synology NAS) respond to SSH_FXP_READDIR with count=0 instead of SSH_FX_EOF for empty directories. Paramiko loops forever in this case — the app hangs indefinitely

Root Cause

Paramiko's listdir_attr does not handle count=0 as end-of-directory. WinSCP and other clients treat count=0 as EOF; this PR replicates that behaviour via a custom _listdir_attr_safe implementation.

Changes

  • Move chdir and listdir_attr onto daemon threads so the UI remains responsive
  • Add _listdir_attr_safe: same as sftp.listdir_attr but breaks on count=0
  • Add _sftp_lock to serialise SFTP calls (paramiko sessions are not thread-safe)
  • Skip special files (sockets, FIFOs, block/char devices) that can hang on stat()
  • Add --debug and --log=<file> CLI flags for diagnostic output
  • Add tests for threaded refresh, special file skipping, and chdir error handling

@Orinks
Orinks force-pushed the fix/sftp-directory-hang branch 2 times, most recently from f8d1a70 to 2c36c6d Compare March 1, 2026 01:44
@gitguardian

gitguardian Bot commented Mar 1, 2026

Copy link
Copy Markdown

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

- Move remote directory listing and chdir onto daemon threads so the UI
  never freezes during SFTP operations
- Fix infinite READDIR loop: some SFTP servers (e.g. Synology NAS) send
  count=0 instead of SSH_FX_EOF for empty directories; paramiko loops
  forever in this case — treat count=0 as EOF (matches WinSCP behaviour)
- Add SFTP lock to serialise calls (paramiko is not thread-safe)
- Skip special files (sockets, FIFOs, devices) that can hang on stat
- Add --debug / --log=<file> flags for capturing diagnostic output
- Add tests for threaded refresh, special file skipping, chdir error handling
@Orinks
Orinks force-pushed the fix/sftp-directory-hang branch from 9df5bdd to 2a0dff7 Compare March 1, 2026 04:32
@Orinks Orinks changed the title fix(sftp): add channel timeout and handle permission errors in list_dir fix(sftp): fix UI freeze and READDIR hang on directories with special files Mar 1, 2026
@Orinks
Orinks merged commit d0dbb7e into dev Mar 1, 2026
6 checks passed
@Orinks
Orinks deleted the fix/sftp-directory-hang branch March 1, 2026 05:17
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