Skip to content

Commit

Permalink
Merge pull request #1134 from Chilledheart/ios_fx_crash_when_stopping
Browse files Browse the repository at this point in the history
ios: fix crash when stopping
  • Loading branch information
Chilledheart authored Oct 23, 2024
2 parents 4d6b46a + a939e82 commit 22fe04e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/ios/extensions/YassPacketTunnelProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,27 @@ - (void)readPackets {
- (void)stopTunnelWithReason:(NEProviderStopReason)reason completionHandler:(void (^)(void))completionHandler {
NSLog(@"tunnel: stop with reason %ld", reason);
stopped_ = true;
if (!worker_) {
// nothing to do, just leave
NSLog(@"tunnel: stopped with empty worker");
completionHandler();
return;
}
absl::AnyInvocable<void()> callback = [self, completionHandler]() {
NSLog(@"worker stopped");
if (context_ == nullptr) {
NSLog(@"tun2proxy destroyed an empty context");
DCHECK(!tun2proxy_thread_);
goto done;
}
Tun2Proxy_Shutdown(context_);
NSLog(@"tun2proxy destroyed");
NSLog(@"tun2proxy shutdown");
tun2proxy_thread_->join();
tun2proxy_thread_.reset();
Tun2Proxy_Destroy(context_);
NSLog(@"tun2proxy destroyed");
context_ = nullptr;
done:
completionHandler();
};
worker_->Stop(std::move(callback));
Expand Down

0 comments on commit 22fe04e

Please sign in to comment.