Skip to content

Return ENOTCONN from Notifier while no server serves - #208

Open
dsfaccini wants to merge 1 commit into
jacobsa:masterfrom
dsfaccini:upstream/notifier-no-server
Open

dsfaccini wants to merge 1 commit into
jacobsa:masterfrom
dsfaccini:upstream/notifier-no-server

Conversation

@dsfaccini

Copy link
Copy Markdown

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

Summary

Notifier.InvalidateInode and InvalidateEntry send their command on an unbuffered channel and wait for the answer (notifier.go L48-L51, L62-L65). Only the goroutine that notifierServer.ServeOps starts receives from that channel, and it stops once the wrapped server's ServeOps returns (L104-L128). A call made before the server starts serving, or after it has stopped, for example after an unmount, blocks forever. A file system that invalidates from a background goroutine leaks that goroutine, or hangs whatever waits for it.

  • InvalidateInode and InvalidateEntry return ENOTCONN while no server wrapped with the Notifier serves: before its ServeOps starts, and once it has returned. They send nothing then.
  • notifierServer.ServeOps waits for its notification goroutine before it returns. A notification in progress when the wrapped server returns is still written to an open connection, because Mount closes the connection only after ServeOps returns (mount.go L93-L97). Every call after ServeOps returns gets ENOTCONN.

Why ENOTCONN

Until ServeOps starts, the server has answered nothing, so the kernel holds nothing of it to invalidate. Once ServeOps has returned, the connection is closing or closed. ENOTCONN is an errno, like the ENOSYS these methods already document, so callers can compare it as they do ENOSYS. Blocking until ServeOps starts was the alternative, but that blocks forever when Mount fails.

Tests

Neither test mounts. Run them with:

go test -run '^(TestNotifierReturnsENOTCONNWhileNothingServes|TestNotifierSendsWhileServing)$' .
  • TestNotifierReturnsENOTCONNWhileNothingServes: both methods return ENOTCONN on a new Notifier, and again after ServeOps of a server wrapped with it has returned.
  • TestNotifierSendsWhileServing: while the wrapped server serves, InvalidateInode writes the notification to the connection, here the write end of a pipe, and returns nil. The test checks the fuse_out_header (notify code 2, unique 0) and the fuse_notify_inval_inode_out body. It passes on master too, and pins the path this PR keeps.

The tests set no timeout of their own. On master (a124548), the first test blocks in its first InvalidateInode call until go test -timeout ends it (excerpt, paths shortened):

=== RUN   TestNotifierReturnsENOTCONNWhileNothingServes
panic: test timed out after 30s
	running tests:
		TestNotifierReturnsENOTCONNWhileNothingServes (30s)
...
goroutine 35 [chan send]:
github.com/jacobsa/fuse.(*Notifier).InvalidateInode(...)
	notifier.go:50
github.com/jacobsa/fuse.checkNotifierENOTCONN(...)
	notifier_test.go:46 +0x64
github.com/jacobsa/fuse.TestNotifierReturnsENOTCONNWhileNothingServes(...)
	notifier_test.go:56 +0xa8
...
FAIL	github.com/jacobsa/fuse	30.146s

With this PR, both tests pass, also under -race.

No test pins the new wait in ServeOps. With the wait removed, TestNotifierReturnsENOTCONNWhileNothingServes still passed in 2000 runs.

Validation

CI runs no go test, so these local runs are the test evidence.

  • macOS 27.2, arm64, Go 1.27.3, and Ubuntu 26.04, Linux 7.0, x86_64, Go 1.26.5: both tests, before and after this PR, with the results above.
  • gofmt -l . prints nothing.
  • go build ./... passes with GOOS=linux and with GOOS=darwin.
  • go vet ./... reports the same findings as on master, with GOOS=linux and with GOOS=darwin, all in files this PR does not touch: unkeyed fusekernel.Protocol literals, reflect.SliceHeader uses and, on linux/arm64, syscall.SYS_DUP2 in samples/flushfs.

Not changed

  • One Notifier wrapped around two servers that serve at the same time. Each notification already goes to whichever server's goroutine takes it, whatever connection that is. With this PR, once the server that started last returns, calls can also return ENOTCONN while the other server still serves.

InvalidateInode and InvalidateEntry sent on an unbuffered channel that only
the goroutine NewServerWithNotifier starts in ServeOps receives from. Before
ServeOps started, or once it had returned, they blocked forever.

They now return ENOTCONN while no server wrapped with the Notifier serves.
ServeOps waits for the notification in progress before it returns, so that
notification is sent on an open connection and every later call returns
ENOTCONN.
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