Skip to content

Push cache invalidations over a client-opened stream - #22

Merged
Umang-Shikarvar merged 1 commit into
mainfrom
feat/server-push-events
Oct 18, 2026
Merged

Umang-Shikarvar merged 1 commit into
mainfrom
feat/server-push-events

Conversation

@Umang-Shikarvar

Copy link
Copy Markdown
Collaborator

Invalidations were delivered by the fileserver dialling a listener on each client. That fails whenever the fileserver cannot reach the client directly (NAT, campus Wi-Fi, home networks, client firewalls), so shared users silently stopped seeing each other's changes.

Clients now open a long-lived WatchEvents stream to their fileserver and the server pushes events down it. The client dials out like every other RPC, so it works through NAT and firewalls and opens no listening port (no OS firewall prompt). The stream uses the existing TLS session and SST stream authentication, and is bound to the authenticated user.

Server:

  • New rpc WatchEvents(WatchEventsRequest) returns (stream WatchEvent). The first message (type 0) confirms the stream; type-0 keepalives every 20s keep NAT mappings open and detect dead connections.
  • A session can hold one stream per running client; all receive events. An open stream marks the session live regardless of the activity TTL.
  • Events go to streams when present and fall back to the callback dial for clients that have none. A stream that falls 256 events behind is closed so the client resyncs instead of stalling the server.
  • UnregisterClient closes the user's streams.

Client:

  • Connect opens the stream; no callback listener is started.
  • Reconnects with backoff (1s..30s), then re-reports its directory and re-fetches it, since events may have been missed.
  • If the session is rejected (expired, IP changed) it says so once; refresh re-registers and reopens the stream.
  • Servers without WatchEvents (Unimplemented) get the old callback listener, so new clients keep working with old fileservers.
  • The session token is guarded by its own lock, as the stream and heartbeat goroutines read it.

Regenerated with protoc 3.21.12, protoc-gen-go v1.36.12 and protoc-gen-go-grpc v1.6.2 (the versions of the committed code).

Invalidations were delivered by the fileserver dialling a listener on
each client. That fails whenever the fileserver cannot reach the client
directly (NAT, campus Wi-Fi, home networks, client firewalls), so shared
users silently stopped seeing each other's changes.

Clients now open a long-lived WatchEvents stream to their fileserver
and the server pushes events down it. The client dials out like every
other RPC, so it works through NAT and firewalls and opens no listening
port (no OS firewall prompt). The stream uses the existing TLS session
and SST stream authentication, and is bound to the authenticated user.

Server:
- New rpc WatchEvents(WatchEventsRequest) returns (stream WatchEvent).
  The first message (type 0) confirms the stream; type-0 keepalives every
  20s keep NAT mappings open and detect dead connections.
- A session can hold one stream per running client; all receive events.
  An open stream marks the session live regardless of the activity TTL.
- Events go to streams when present and fall back to the callback dial
  for clients that have none. A stream that falls 256 events behind is
  closed so the client resyncs instead of stalling the server.
- UnregisterClient closes the user's streams.

Client:
- Connect opens the stream; no callback listener is started.
- Reconnects with backoff (1s..30s), then re-reports its directory and
  re-fetches it, since events may have been missed.
- If the session is rejected (expired, IP changed) it says so once;
  refresh re-registers and reopens the stream.
- Servers without WatchEvents (Unimplemented) get the old callback
  listener, so new clients keep working with old fileservers.
- The session token is guarded by its own lock, as the stream and
  heartbeat goroutines read it.

Regenerated with protoc 3.21.12, protoc-gen-go v1.36.12 and
protoc-gen-go-grpc v1.6.2 (the versions of the committed code).
@Umang-Shikarvar
Umang-Shikarvar merged commit 67fa48a into main Oct 18, 2026
1 check passed
@Umang-Shikarvar
Umang-Shikarvar deleted the feat/server-push-events branch October 18, 2026 20:32
Umang-Shikarvar added a commit that referenced this pull request Oct 18, 2026
Restores the tree of 84f23f6 (Merge pull request #16), undoing PRs #19,
#20, #21 and #22. That work is preserved on branch fix_cache_callback.
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