Skip to content

Fix core start/stop deadlocks and race conditions in traffic stats - #212

Open
OneMiny wants to merge 1 commit into
2dust:mainfrom
OneMiny:fix/core-start-stop-from-main
Open

OneMiny wants to merge 1 commit into
2dust:mainfrom
OneMiny:fix/core-start-stop-from-main

Conversation

@OneMiny

@OneMiny OneMiny commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Startup and shutdown callbacks can call back into the controller while it holds its lifecycle lock. Traffic stats can also be read while the core is being initialized or cleared.

The controller now publishes state after successful startup and delivers ordered notifications outside its lock. Stats reads use the same lock as Start and Stop. TUN descriptor setup is serialized through startup. Duplicate Start calls and invalid JSON preserve the previous descriptor.

Check Before After
Stop from Startup and Start from Shutdown through JNI Each timed out in 3 of 3 runs Each passed in 3 of 3 runs
Stats reads during Start and Stop Go race detector reported concurrent access Passed 30 shuffled runs with -race per dependency set
Duplicate Start or invalid JSON through JNI Both overwrote xray.tun.fd in 3 of 3 runs Both preserved the value in 3 of 3 runs
Listener cleanup after a failed Start Listener released and retry succeeded Listener released and retry succeeded
Loopback HTTP and traffic counter reset through JNI Passed in 3 of 3 runs Passed in 3 of 3 runs

JNI runs used a Android 12. The Go fixture and Java harness ran separately from the production patch. Generator output preserves the Java method signatures. SetIsRunning has no effect. Go callers use controller methods for the running state and callback handler.

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