feat(vpn): defer tunnel cache clear via on-disk marker#522
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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.ClearTunnelCacheto write alantern.cache.clearmarker 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.
WendelHime
approved these changes
Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ClearTunnelCacheforced a disconnect to free the file and did not reopen the tunnel.This change replaces that behavior with a deferred-clear marker:
ClearTunnelCachenow 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.ClearTunnelCachesignals the caller to restart the tunnel so the deferred clear is applied immediately;LocalBackend.ClearTunnelCacheperforms that restart.clear-cacheCLI subcommand exposes the operation over IPC.