🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.freebsd.bugs
Article #468

[Bug 300785] [fusefs]: timed-out writes return bogus EINTR and the buffer is re-dirtied without recording the error

#468
From: bugzilla-noreply
Date: Sun, 15 Nov 2026 02:20
135 lines
6969 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300785

            Bug ID: 300785
           Summary: [fusefs]: timed-out writes return bogus EINTR and the
                    buffer is re-dirtied without recording the error
           Product: Base System
           Version: 15.1-STABLE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: e@4779.name

Created attachment 277313
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277313&action=edit
fuse_io.c: record ETIMEDOUT on the buffer, reserve B_EINTR for genuine EINTR
(git diff, main and stable/15)

Environment:

FreeBSD 15.1-RELEASE-p6 amd64. The cited code is identical in
stable/15 (release/15.1.0) and current main. FUSE server: bcachefs
over FUSE (https://github.com/e4779/bcachefs-freebsd), default
daemon_timeout (60 s). Observed live in production, then confirmed
by code reading and a deterministic test.


Description:

fuse_ipc.c waits daemon_timeout seconds for a reply and then returns
ETIMEDOUT (sys/fs/fuse/fuse_ipc.c:436-444, main; stable/15
identical). The write path discards that knowledge.

fuse_io_strategy (sys/fs/fuse/fuse_io.c:896-904) receives ETIMEDOUT,
re-dirties the buffer (bdirty, clears B_DONE) and records nothing: no
BIO_ERROR, no b_error. For synchronous callers (!B_ASYNC) it sets the
B_EINTR flag - for both EINTR and ETIMEDOUT. bwait
(sys/kern/vfs_bio.c:4574-4577) then converts B_EINTR into a bare EINTR
return.

Consequences:

1. A synchronous writer gets EINTR for a syscall that was never
   signalled. EINTR reads as "retry me": applications retry, and each
   retry burns another full daemon_timeout window inside
   fdisp_wait_answ. In our production this surfaced as an endless
   EINTR-retry loop (qbittorrent/libtorrent retrying a write against a
   healthy daemon).

2. An asynchronous writeback buffer is re-dirtied with no error marker
   and no retry scheduling; the failure is invisible to every consumer
   reading b_error or BIO_ERROR.

3. fsync(2): vn_fsync_buf (sys/kern/vfs_vnops.c:3245; maxretry = 10000
   at :3253) reads b_error == 0 on the re-dirtied buffer and keeps
   flushing; each pass costs one daemon_timeout window; after maxretry
   passes it returns EAGAIN instead of the real error.

What we ruled out:

- The FUSE server. At every observed wedge the daemon was alive and
  serving: thread stacks on both sides show the client parked in
  fdisp_wait_answ inside fuse_vnop_write / fuse_vnop_read while the
  daemon slept in poll/accept; the daemon web UI answered 200 during
  the same wedge, and dtrace measured ~65k ops/s throughput.

- Server-side reply-path bugs (lost writev, MT lockups) existed and
  were fixed in our server earlier; this wedge class survived those
  fixes.

- A non-serving daemon is detectable and distinct: with the daemon
  SIGSTOPped, ops time out with ETIMEDOUT after one window (verified
  on a test mount).


How-To-Repeat:

1. Deterministic test against a stock kernel. The gtest suite
   tests/sys/fs/fusefs/fusefs_timeout.cc (full patch attached:
   fusefs-tests-etimedout.patch) mounts a mock
   FUSE server that delays FUSE_WRITE replies beyond daemon_timeout;
   a writer then times out. On stock fusefs(4),
   Timeout.append_lane_etimedout fails: the writer observes EINTR and
   the buffer stays dirty. With the attached fix the test passes
   (ETIMEDOUT in one window, 3.0 s wall-clock assert); the
   neighbouring Fsync and Interrupt suites pass unchanged on both
   kernels.

2. Live stacks from a production wedge (2026-11-06, qbittorrent
   writing):

       client: fdisp_wait_answ+0x150
           <- fuse_write_directbackend <- fuse_io_strategy
           <- bufwrite <- fuse_write_biobackend <- fuse_vnop_write
           <- sys_write
       daemon: FUSE reader in poll, control socket in accept, workers
           asleep

   Full procstat -k excerpts of both sides attached.


Fix:

Record the error on the buffer and reserve B_EINTR for genuine EINTR.
In the timeout branch of fuse_io_strategy:

    bp->b_ioflags |= BIO_ERROR;
    bp->b_error = ETIMEDOUT;

keep bdirty so data is not lost. Our working patch covers all three
write lanes (IO_SYNC, discontiguous appends, fsync) and includes the
test suite above. Attached as a git diff
(fusefs-151-inverse-fuse_io.patch; tests patch attached separately).

Related but distinct:
- bug #236474 (fsync returns asynchronously - completion semantics, not
timeout errno handling);
- bug #293028 (EINTR in cp(1) and
copy_file_range(2) over fuse - userland copy path).

Note on tooling: prepared with LLM-assisted tooling under my
supervision.

-- 
You are receiving this mail because:
You are the assignee for the bug.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID: <bug-300785-227@https.bugs.freebsd.org/bugzilla/>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: bugzilla-noreply@freebsd.org
Newsgroups: muc.lists.freebsd.bugs
Subject: [Bug 300785] [fusefs]: timed-out writes return bogus EINTR and the
 buffer is re-dirtied without recording the error
Date: Sun, 15 Nov 2026 02:20:07 +0000
Organization: Newsgate at muc.de e.V.
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-300785-227@https.bugs.freebsd.org/bugzilla/>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="55586"; mail-complaints-to="news-admin@muc.de"
X-Original-To: bugs@mlmmj.nyi.freebsd.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1794709207;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=piY7iHPNGrq1UyfFUZ88MN9vDHC9WBzDWsXK5SHzgUk=;
	b=XHryZJVNLzsSi4z5myta7l7ZiwOjO4DQ3nPlsBYdsKwbuB1AGXwCzVOjMaAfYeLrYB16n4
	75anEkcM/x/+vyAf8MyWszbDj6NG4tPLrZ6qHLw/QHZm/r8TfG6i5RkZWUWoefzfuoJqjm
	MhQbqkXsjQu0iic0LAQDWcCOSP75dtIOIc6R9Eaew4l+8YOc2Dso/Pq81Uam6nAgmal9gj
	RzqgIxnIF9awr5MT1mtzZ0IeY4YdF5jPtpMqj9iHCCWazz/bSznNOwryVteD+L5GSaflXL
	lEQ5rhRni80NgTIpPCTawAxNFcsgDM0qv05222NHWFO92xHiSNMAMgTZVDWZjw==
X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f
Auto-Submitted: auto-generated
Precedence: list
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes