Repository navigation
Conversation
A started WireGuard device runs its timers every 250 ms for as long as it lives, and the outbound kept its device until the core stopped. A profile that had used a WireGuard outbound once therefore woke an idle phone four times a second. The outbound now closes its device once no flow has been open and no caller has taken it for five minutes; the next flow starts a new device with a fresh handshake. A device whose peers set keepAlive is kept, since that asks for the path to stay open while idle. Client::open_flows counts the flows holding or waiting for a place, which the idle check reads.
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.
Problem
The vendored gotatun device runs
handle_timersevery 250 ms for as long as it lives (vendor/gotatun/src/device/mod.rs), andWireguardOutboundkeeps its cached device until the core stops. So a profile that used a WireGuard outbound once — even for a single DNS query — wakes an idle phone four times a second for the rest of the session. On iOS/Android that shows up as background battery drain on a tunnel that carries no WireGuard traffic.Change
xray-wireguard:Client::open_flows()— flows holding or waiting for a place (open TCP/UDP flows, unspentTcpSlots, queued TCP opens).xray-core-rsWireGuard outbound: each started device gets a small task that closes it once it has had no open flow, and no caller has taken it, for 5 minutes (IDLE_CLOSE). The next flow starts a new device with a fresh handshake. The idle time counts from the lastclient()call, so a caller that just took the device is never handed a closed one. The task holds only aWeak<Owner>and a session number, and ends when the device is closed or replaced.keepAliveis never closed, since that asks for the path to stay open while idle.Making gotatun's timer loop deadline-driven would also fix this, but it touches the vendored fork; this keeps the change in our own crates.
Tests
wireguard_device_without_flows_is_closed_after_idle_and_restarts— kept while a flow is open (15 min), closed after idle, next flow starts a new device.wireguard_idle_time_counts_from_the_last_callerwireguard_device_with_keepalive_is_kept_while_idleThe first two fail with the idle task disabled.
cargo fmt --check,cargo clippy -p xray-core-rs -p xray-wireguard --all-targets --all-features -D warnings, andcargo test -p xray-wireguard -p xray-core-rs --all-targetspass.