Repository navigation
fix(gateway): refresh WireGuard handshakes off hot path - #740
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors WireGuard wg show <iface> latest-handshakes collection so it no longer runs under the ProxyState hot-path lock, by introducing a dedicated cache that is refreshed asynchronously.
Changes:
- Add
LatestHandshakesCachehelper to fetch/parse and store a process-local snapshot oflatest-handshakes. - Preload the cache at startup and refresh it periodically from a background task using
spawn_blocking. - Keep
ProxyState::latest_handshakes()as a snapshot-read wrapper and add a parser unit test.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| gateway/src/main_service/handshakes.rs | Introduces the LatestHandshakesCache, parsing, and a basic parser test. |
| gateway/src/main_service.rs | Wires the cache into proxy state/inner, preloads it, starts the refresh task, and routes latest_handshakes() through the cache. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
kvinwang
force-pushed
the
fix/gateway-handshake-cache
branch
2 times, most recently
from
June 25, 2026 03:00
0c121b8 to
5b5d616
Compare
kvinwang
force-pushed
the
fix/gateway-handshake-cache
branch
from
June 25, 2026 03:04
5b5d616 to
d8c47f9
Compare
Comment on lines
+40
to
+46
| pub(crate) async fn refresh(&self) -> Result<()> { | ||
| let interface = self.interface.clone(); | ||
| self.cell | ||
| .refresh_blocking(move || fetch_latest_handshake_timestamps(&interface)) | ||
| .await | ||
| .map_err(|err| anyhow::anyhow!("{err}"))?; | ||
| Ok(()) |
Comment on lines
+49
to
+53
| pub(crate) fn latest(&self, stale_timeout: Option<Duration>) -> Result<HandshakesWithAge> { | ||
| let snapshot = self.cell.get()?; | ||
| add_elapsed_time(snapshot.value(), stale_timeout) | ||
| } | ||
| } |
kvinwang
enabled auto-merge (squash)
June 25, 2026 06:38
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
cached-cellcrate withTtlCell<T>: a small OnceCell/LazyCell-style abstraction for TTL-bound cached snapshots.TtlCellowns the generic mechanics: storage, freshness checks, stale reads,spawn_blockingrefresh, and one-shot periodic refresh scheduling.LatestHandshakesCachenow only defines how to fetch/parsewg show <iface> latest-handshakesand delegates caching/expiration tocached-cell.wg showcommand underProxyStatelock.Tests
cargo check --manifest-path gateway/Cargo.tomlcargo test -p cached-cellcargo test --manifest-path gateway/Cargo.toml handshakes -- --nocapture