Skip to content

refactor(fuse): delete ReadAheadManager.Stop and its channel (#376) - #382

Merged
scttfrdmn merged 1 commit into
mainfrom
chore/readahead-stop-376
Aug 8, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
chore/readahead-stop-376

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #376.

The mount context is the only shutdown signal now. ReadAheadManager.Stop, its stopCh, and its
sync.Once are deleted.

What #376 asked

#179 fixed the real leak — five goroutines per mount surviving every unmount, each keeping its
FileSystem and through it the backend and the cache reachable — by making the mount context a stop
signal, so the cancelMount() the adapter already performs is what ends them. What was left over was
an exported lifecycle method that nothing outside tests called. #376 named two defensible resolutions
and asked for one to be picked:

  1. Call it from Unmount, keeping cancellation as a backstop.
  2. Unexport it or document it as test-only.

(1) is rejected for the reason the issue gives: it reintroduces exactly the "someone must remember to
call this on every mount path" obligation whose being missed was the leak.

Why (2) became a deletion

The issue's case for keeping it was that stopCh expresses the one thing cancellation cannot —
stopping a manager whose context the caller does not own, "which is a test's situation and nothing
else's."

Plausible, and false. Neutering the channel's select arm broke no test:

$ # stopCh arm replaced with a nil channel receive
$ go test -race -count=1 ./internal/fuse/
ok  github.com/scttfrdmn/objectfs/internal/fuse  2.973s

So no test needed it either. A second shutdown path with no caller on either side is not a seam
worth preserving — two ways to stop the same goroutines is how they came to be stopped by neither.

The tests that wanted the workers out of the way now cancel a mount context of their own, through
readPathFixture.stopReadAhead, so the test shutdown and the production one are the same code path.
The deleted Stop never was. The ten defer ram.stop() calls in optimizations_test.go were pure
redundancy against t.Context() and are gone.

The helper's comment says what a mutation showed it is worth

Removing all three stopReadAhead() calls leaves the suite green over twelve runs, and the comment
says so. Each caller invokes it during setup, before any read has established a sequential pattern,
and then nils or replaces the manager — and that assignment is what stops new prefetches from being
scheduled. It is kept for stopping what it replaces and for exercising the real shutdown path, not
for preventing a race it does not currently prevent. Claiming otherwise is how a comment becomes the
next reader's wrong premise, which is the shape of the defect this PR is closing.

Verification

  • go build ./..., go vet ./..., make lint — 0 issues
  • full go test -race -count=1 ./... — pass; ./internal/fuse/ -count=3 — pass
  • coverage gate: 36 packages at or above floor, internal/fuse 68.5% against a floor of 67
  • mutation: removing the mount.Done() arm from both workers fails
    TestReadAhead_MountCancellationStopsTheWorkers with "25 read-ahead goroutines still running after
    every mount context was canceled"

Not a behaviour change. internal/fuse has no importer outside this repository and the method had no
caller inside it.

The mount context is the only shutdown signal now. Cancel it and the prefetch workers
and the cleanup ticker return; there is nothing else to call.

#179 fixed the leak — five goroutines per mount surviving every unmount, each keeping its
FileSystem and through it the backend and the cache reachable — by making the mount context
a second stop signal, so the `cancelMount()` the adapter already performs is what ends them.
What was left over was an exported lifecycle method that nothing outside tests called: not
MountManager.Unmount, not Adapter.Stop, not anything on the unmount path. That is the worst
of the available states, because a reader finds it and reasonably assumes Unmount calls it.

Calling it from Unmount was the other option and is rejected: it reintroduces exactly the
"someone must remember this on every mount path" obligation whose being missed was the leak.

The issue proposed unexporting it and keeping it for tests, and a mutation refuted that
premise. The stated justification was that stopCh expresses the one thing cancellation
cannot — stopping a manager whose context the caller does not own. Plausible, and false:
neutering the channel's select arm broke no test, so no test needed it either. A second
shutdown path with no caller on *either* side is not a seam worth preserving. Two ways to
stop the same goroutines is how they came to be stopped by neither.

The tests that wanted the workers out of the way now cancel a mount context of their own,
via readPathFixture.stopReadAhead, so the test shutdown and the production one are the same
code path — which the deleted Stop never was. The ten `defer ram.stop()` calls in
optimizations_test.go were pure redundancy against t.Context() and are gone.

That helper's doc comment says what a mutation showed it is worth rather than what it looks
like it is worth: removing all three calls leaves the suite green over twelve runs, because
each caller invokes it during setup before any sequential pattern exists and then replaces
or nils the manager, which is the assignment that actually stops new prefetches. It is kept
for stopping what it replaces and for exercising the real shutdown path, not for preventing
a race it does not currently prevent.

Mutation-verified: removing the `mount.Done()` arm from both workers fails
TestReadAhead_MountCancellationStopsTheWorkers with "25 read-ahead goroutines still running
after every mount context was canceled".

Not a behaviour change. internal/fuse has no importer outside this repository and the method
had no caller inside it. internal/fuse coverage 68.5% against its floor of 67.
@scttfrdmn
scttfrdmn merged commit 7695ca2 into main Aug 8, 2026
33 checks passed
@scttfrdmn
scttfrdmn deleted the chore/readahead-stop-376 branch August 8, 2026 07:50
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.

ReadAheadManager.Stop has no production caller; the unmount path relies on context cancellation alone

1 participant