Skip to content

deviceconnect: connection-scoped cleanup for call instances#1

Open
kavya-chennoju wants to merge 1 commit intoericvh:feature/deviceconnectfsfrom
kavya-chennoju:feature/deviceconnectfs-close-ctl
Open

deviceconnect: connection-scoped cleanup for call instances#1
kavya-chennoju wants to merge 1 commit intoericvh:feature/deviceconnectfsfrom
kavya-chennoju:feature/deviceconnectfs-close-ctl

Conversation

@kavya-chennoju
Copy link
Copy Markdown

@kavya-chennoju kavya-chennoju commented Apr 29, 2026

Summary

Reading clone allocates a numbered call directory under functions/<fn>/
that nothing reaps — every invocation leaks one numbered subdir for the
lifetime of the server.

Tie each call dir's lifetime to the 9P connection that allocated it:
a per-connection registry on DCFS is drained from a ConnClosed hook
on a small Fsrv wrapper (dcSrv). When a client unmounts, crashes, or
drops its TCP connection, every call dir it allocated goes away with it
— the same idiom Plan 9 uses for /net/tcp and /srv.

No client-side cleanup ritual required; the CLI just mounts and unmounts.

Test plan

  • go test ./p/srv/examples/deviceconnect/ ./cmd/go9p-deviceconnect/ -race -count=20 (160 runs, no flakes)
  • New TestDeviceConnect_DisconnectCleansUpCalls allocates dirs, drops the allocating connection, asserts a fresh client cannot walk into them
  • Falsifiability verified by independently disabling (a) the registration call in funcCloneFile.Read and (b) the ConnClosed body — both produce the expected failure
  • End-to-end stress: 1000 sequential CLI calls against a live server leave 0 call dirs in the namespace
  • All existing tests pass unchanged

@ericvh
Copy link
Copy Markdown
Owner

ericvh commented May 1, 2026

Embarrassed to say you are ahead of my in actually testing this out.

Normal 9p semantics are that the session should be garbage collected when the session gets closed (usually when the fd itself gets garbage collected) -- so it shouldn't need an explicit close command in the ctl file, but I'm not sure the garbage collection is built correctly in the current file server.

Reading clone allocates a numbered call directory under functions/<fn>/
that nothing reaps. Tie the call dir's lifetime to the 9P connection
that allocated it: a per-connection registry of allocated dirs is
drained from a ConnClosed hook on a small Fsrv wrapper (dcSrv). When
a client unmounts, crashes, or drops its TCP connection, every call
dir it allocated goes away with it — the same idiom Plan 9 uses for
/net/tcp and /srv.

No client-side cleanup ritual needed; the CLI just mounts and unmounts.

Includes a regression test that allocates dirs, drops the allocating
connection, and asserts a fresh client can no longer walk into them.
@kavya-chennoju kavya-chennoju force-pushed the feature/deviceconnectfs-close-ctl branch from ca02ccb to 20d565f Compare May 1, 2026 17:02
@kavya-chennoju kavya-chennoju changed the title deviceconnect: add ctl close for call instances deviceconnect: connection-scoped cleanup for call instances May 1, 2026
@kavya-chennoju
Copy link
Copy Markdown
Author

Ah 🤦‍♀️ , that makes clean up easier didn't realize there were already lifecycle hooks, wired them up.

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.

2 participants