Skip to content

fix(vpn): retain stopJob and reset isStopping synchronously - #44

Merged
Hidden-Node merged 1 commit into
mainfrom
advisor/014-isstopping-stopscope-lifecycle
Jul 24, 2026
Merged

fix(vpn): retain stopJob and reset isStopping synchronously#44
Hidden-Node merged 1 commit into
mainfrom
advisor/014-isstopping-stopscope-lifecycle

Conversation

@Hidden-Node

Copy link
Copy Markdown
Owner

Plan 014. Previously stopVpn() used a local CoroutineScope whose Job was unreachable from the service fields; a low-memory process pause between state=DISCONNECTED and stopSelf() could GC the cleanup coroutine mid- teardown, leaving Go core / TUN fd / WakeLock / NetworkCallback live. isStopping also stayed true until onDestroy(), blocking a fresh connect() during that gap. Fix: retain stopJob on the service so onDestroy() can join it, reset isStopping in a finally block inside the launch lambda so it goes false when teardown actually finishes, and add a DISCONNECTING guard to VpnManager.connect() so the UI can't race the disconnect dispatch.

Plan 014. Previously stopVpn() used a local CoroutineScope whose Job was
unreachable from the service fields; a low-memory process pause between
state=DISCONNECTED and stopSelf() could GC the cleanup coroutine mid-
teardown, leaving Go core / TUN fd / WakeLock / NetworkCallback live.
isStopping also stayed true until onDestroy(), blocking a fresh
connect() during that gap. Fix: retain stopJob on the service so
onDestroy() can join it, reset isStopping in a finally block inside
the launch lambda so it goes false when teardown actually finishes,
and add a DISCONNECTING guard to VpnManager.connect() so the UI can't
race the disconnect dispatch.
@Hidden-Node
Hidden-Node merged commit 3ffb861 into main Jul 24, 2026
0 of 2 checks passed
@Hidden-Node
Hidden-Node deleted the advisor/014-isstopping-stopscope-lifecycle branch July 24, 2026 14:31
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.

1 participant