From fe9772b178575fcab93de09fc61c2f13db7db1a8 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 2 Oct 2026 00:49:30 -0300 Subject: 9ns: a dead mount's entry is invalidated from a thread of its own, never from the thread serving the mount, which a LOOKUP holding the parent directory's lock may be waiting on (a cat of a dead session's index hung for good) Co-Authored-By: Claude Opus 5.5 --- 9ns/src/bridge.zig | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/9ns/src/bridge.zig b/9ns/src/bridge.zig index 97e0882..b94ef78 100644 --- a/9ns/src/bridge.zig +++ b/9ns/src/bridge.zig @@ -2406,13 +2406,28 @@ fn dialErrno(e: DialError) linux.E { /// /// Best effort, and deliberately not fatal: a notification the kernel /// rejects leaves exactly the old behaviour (ESTALE until the cache -/// expires), which is degraded, not broken. Writing to /dev/fuse from this -/// thread is safe — a notification carries `unique = 0`, and the workers -/// already write their own replies to the same fd. +/// expires), which is degraded, not broken. +/// +/// Never sent from this thread, the one serving the mount: the kernel +/// takes the parent directory's lock to invalidate the entry, and a LOOKUP +/// holding that lock may be waiting on a reply only this thread would send +/// (a `cat` of the dead session's index, seen to hang for good). A thread +/// of its own sends it while this one goes on answering ESTALE; one that +/// cannot be made skips it. fn retireEntry(m: *Mount) void { - fuse.notifyInvalEntry(m.b.fuse_fd, m.parent_node, m.entry_name) catch |e| { - if (m.debug) std.debug.print("9ns: [{s}] could not invalidate its entry: {t}\n", .{ m.name, e }); + const Notify = struct { + fn send(fd: i32, parent: u64, name: []u8) void { + defer std.heap.page_allocator.free(name); + fuse.notifyInvalEntry(fd, parent, name) catch {}; + } + }; + const name = std.heap.page_allocator.dupe(u8, m.entry_name) catch return; + const thread = std.Thread.spawn(.{}, Notify.send, .{ m.b.fuse_fd, m.parent_node, name }) catch { + std.heap.page_allocator.free(name); + if (m.debug) std.debug.print("9ns: [{s}] could not invalidate its entry\n", .{m.name}); + return; }; + thread.detach(); } // -- pure helpers (unit-tested) ------------------------------------------------------------ -- cgit v1.3