Skip to content

Commit 338e5da

Browse files
authored
perf(mobile): lower StopClient join timeout from 3s to 1s and log slow shutdown (#20)
When the user taps Disconnect, `GooseRelayVpnService.stopVpn()` waits up to **5 seconds** (`stopThread.join(5000L)`) for Go's `StopClient()` to return. Inside `StopClient()`, after the carrier `cancel()` and SOCKS listener close, it waits *another* up to **3 seconds** on `<-clientDone`. The inner 3s timeout is redundant with the outer 5s join. On a healthy disconnect where the carrier shuts down in <200ms (the common case), the user still sees ~3s of "DISCONNECTING" + 500ms fade ≈ **3.5s**, where the inner 3s timeout is the sole contributor — the outer 5s never kicks in. **Change:** Lower the inner `<-clientDone` wait from `3s → 1s`. If the carrier takes longer than 1s, log it and return — the outer 5s join still caps total disconnect at a sane value. Healthy disconnect drops from ~3.5s → ~1.5s with no behavioral regression. The new `[client] carrier shutdown exceeded 1s` log line surfaces slow shutdowns for debugging without changing `StopClient`'s gomobile API surface (which would ripple to Kotlin callers). ## Files changed - `mobile/mobile.go` — single block replacement (+9/-1) ## CI gates to watch - `go vet` (Linux — `syscall.Dup` resolves; the Windows-only vet error in `dupFd` is pre-existing, unrelated) - AAR build (`bash ./android/build_go_mobile.sh`) - `./gradlew :app:assembleDebug`
1 parent 2b0ba1b commit 338e5da

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

mobile/mobile.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,15 @@ func StopClient() {
239239
if done != nil {
240240
select {
241241
case <-done:
242-
case <-time.After(3 * time.Second):
242+
case <-time.After(1 * time.Second):
243+
// The carrier shutdown took longer than 1s. The outer
244+
// Android caller (GooseRelayVpnService.stopVpn) caps total
245+
// disconnect with a 5s outer join, so we return promptly
246+
// here and let the outer caller decide whether to log a
247+
// "stop timed out" message. StopTun/StopTunBridge below are
248+
// idempotent and safe to call even if the carrier is still
249+
// winding down.
250+
log.Printf("[client] carrier shutdown exceeded 1s, proceeding with TUN teardown")
243251
}
244252
}
245253

0 commit comments

Comments
 (0)