Skip to content

Destroy per-file and per-I/O condition variables - #401

Open
MakFly wants to merge 2 commits into
libfuse:masterfrom
MakFly:fix/condition-variable-lifetime
Open

MakFly wants to merge 2 commits into
libfuse:masterfrom
MakFly:fix/condition-variable-lifetime

Conversation

@MakFly

@MakFly MakFly commented Oct 30, 2026

Copy link
Copy Markdown

SSHFS initializes condition variables for each open file, asynchronous read chunk and synchronous write, but releases their storage without calling pthread_cond_destroy(). Repeated I/O therefore accumulates resources on implementations with allocated condition variables, including Cygwin. A long-running SSHFS-Win 3.5.20357 mount was observed with over 4.5 million Windows handles and continuing growth.

Add the four missing destroy calls at the existing lifetime boundaries: read-chunk destruction, failed open, file release and completion of a synchronous write. No transport, reconnect or mount behavior changes.

The new unit test includes the real sshfs.c cleanup paths and counts successful condition-variable initializations/destructions. It requires neither FUSE mounting nor an SSH server, and detects the imbalance even on glibc, where condition variables do not allocate Windows-style handles. It covers six cases: empty and failed reads, failed open, release after disconnect, and empty and failed synchronous writes.

Validation on Debian trixie / GCC 14.2 / GLib 2.84.4 / libfuse 3.17.2:

  • All six regression cases fail on the original source with an unmatched condition variable (two in the release case, which also owns readahead).
  • Both Meson unit suites pass after the fix.
  • Both suites also pass with AddressSanitizer and UndefinedBehaviorSanitizer.
  • Unit targets compile with warnings treated as errors.

Windows/Cygwin end-to-end stress validation has not been run. The observed desktop stutters are not claimed to be proven consequences of this specific leak.

Related reports: winfsp/sshfs-win#285.
The same cleanup calls were previously proposed by @TongLi-Galaxy as part of winfsp/sshfs-win#478. This PR brings the focused lifetime fix upstream, with regression coverage, rather than carrying additional Windows connection/recovery changes.

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