[wip]refactor: introduce AppContext to replace global CancellationToken#1079
Draft
[wip]refactor: introduce AppContext to replace global CancellationToken#1079
Conversation
…emove print_and_exit! macros in favor of Result
a1c83b9 to
795ddfe
Compare
Contributor
🚀 TUN Throughput Benchmark Results📊 Test Environment
❌ Benchmark FailedThe TUN benchmark test failed to complete. Check the workflow logs for details. Baseline test succeeded:
Common causes:
🤖 Benchmark run on GitHub Actions CI • |
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.
What does this PR do?
SHUTDOWN_TOKENstatic variable andshutdown()function fromclash-lib/src/lib.rs.AppContextstruct inclash-lib/src/app/context/mod.rsto properly manage lifecycle and cancellation signals across components.AppContextvia dependency injection to core runtime components (InboundManager,TunRunner,DnsRunner,ApiRunner), replacing their internal standalone cancellation tokens.print_and_exit!macro and directstd::process::exitcalls (e.g. in config rule parsing, resolver initialization, and outbound manager) with returningResult::Err(crate::Error)for graceful error propagation, which is vital for usingclash-libas a robust library.This provides a cleaner, more idiomatic architecture that prevents sudden process crashes on configuration errors and gives the library consumer full control over component lifecycle.