Skip to content

feat(vpn): defer tunnel cache clear via on-disk marker#522

Merged
garmr-ulfr merged 3 commits into
mainfrom
clear-cache-marker
Jun 11, 2026
Merged

feat(vpn): defer tunnel cache clear via on-disk marker#522
garmr-ulfr merged 3 commits into
mainfrom
clear-cache-marker

Conversation

@garmr-ulfr

@garmr-ulfr garmr-ulfr commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Clearing the tunnel cache while it is held by an active tunnel — or owned by another process for mobile — cannot delete the file in place. Previously ClearTunnelCache forced a disconnect to free the file and did not reopen the tunnel.

This change replaces that behavior with a deferred-clear marker:

  • ClearTunnelCache now writes an on-disk marker (lantern.cache.clear) when the tunnel is active or the cache file is owned by another process, instead of forcing a disconnect.
  • The next tunnel start consumes the marker and retries the deletion before the cache flock is acquired, then removes the marker on success.
  • When the tunnel is active, ClearTunnelCache signals the caller to restart the tunnel so the deferred clear is applied immediately; LocalBackend.ClearTunnelCache performs that restart.
  • A new clear-cache CLI subcommand exposes the operation over IPC.

Clearing the tunnel cache while it is held by an active tunnel (or owned
by another process) cannot delete the file in place. Instead of forcing a
disconnect, ClearTunnelCache now writes a marker that the next tunnel
start consumes to retry the deletion before the cache flock is acquired,
and signals callers to restart the tunnel to apply a deferred clear.

Add a clear-cache CLI subcommand exposing this over IPC.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes tunnel cache clearing from an immediate-delete (with forced disconnect) to a deferred-delete model using an on-disk marker, enabling cache deletion to be retried safely on the next tunnel start (before acquiring the cache flock). It also exposes the operation via IPC and a new lantern clear-cache CLI subcommand, and updates the backend to restart the tunnel when a connected-tunnel clear is requested.

Changes:

  • Reworked VPNClient.ClearTunnelCache to write a lantern.cache.clear marker when the tunnel is active, and added marker consumption during tunnel initialization.
  • Added shared helpers for cache file removal + marker write/consume, plus tests for the marker consumption behavior.
  • Updated IPC/backend/CLI wiring to call the new clear-cache behavior and restart the tunnel when requested.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vpn/vpn.go Changes cache clear API to return a restart hint and defer clear via marker when tunnel is active.
vpn/vpn_test.go Updates cache-clear tests and adds coverage for consuming the deferred-clear marker.
vpn/tunnel.go Consumes the deferred-clear marker before acquiring the cache flock during tunnel init.
vpn/boxoptions.go Adds marker path + helper functions for removing the cache and writing/consuming the marker.
ipc/server.go Updates the IPC handler to call the new backend ClearTunnelCache() signature.
ipc/client.go Updates the IPC client method docs to reflect restart-on-connected behavior.
cmd/lantern/vpn.go Adds CLI execution function for the new cache-clear command.
cmd/lantern/lantern.go Registers the new clear-cache CLI subcommand and routes it to the IPC client call.
backend/radiance.go Updates backend cache clear to restart VPN when the VPNClient indicates it should.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread vpn/vpn.go
Comment thread vpn/boxoptions.go Outdated
@garmr-ulfr garmr-ulfr marked this pull request as ready for review June 10, 2026 22:44
@garmr-ulfr garmr-ulfr merged commit ccc35dc into main Jun 11, 2026
2 checks passed
@garmr-ulfr garmr-ulfr deleted the clear-cache-marker branch June 11, 2026 15:25
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.

3 participants