Exiting Tor thread crashes certain devices
Closed this issue · 7 comments
The tor thread dies after the app goes into the background so I have been experimenting with how best to handle this. I finally resorted to force resigning the tor thread whenever the app goes into the background, and then automatically reconnecting tor when app enters foreground. This works great on my device and on all simulators, however on newer iPhone models it seems to cause a crash at the same time as the log outputs [notice] Interrupt: exiting cleanly.
I have seen this code in the OnionBrowser repo:
/**
Experimental Tor shutdown.
*/
func stopTor() {
print("[\(String(describing: type(of: self)))] #stopTor")
// Under the hood, TORController will SIGNAL SHUTDOWN and set it's channel to nil, so
// we actually rely on that to stop Tor and reset the state of torController. (we can
// SIGNAL SHUTDOWN here, but we can't reset the torController "isConnected" state.)
torController?.disconnect()
torController = nil
// More cleanup
torThread?.cancel()
torThread = nil
state = .stopped
}
Have you had success with it? Do you have any idea why resigning the Tor thread may cause a crash on some devices but not others?
Yeah, actually that code works just fine for us. Check our AppDelegate
for resuming:
I'm curious: What's the difference to your code? When you change to our way, does everything work for you?
Just from your description, it sounds like a race condition. Maybe newer devices are too fast?
The only difference between our code was the torThread.cancel()
, I tried that too with the same result.
I am curious have you tested on iPhone 11 models?
I think you are correct, they are too damn fast. I am going to try one more method but will probably give up at that point as I am stumped, frustrating that it works so well on my device (but not my bosses/users).
Currently on iPhone XS. No problems there.
Did you cross-check with Onion Browser? The one in the app store (2.4.0) contains that code.
There was also some upheaval with iOS 13.2. closing apps too fast:
https://www.imore.com/ios-132-may-have-broken-multitasking
Maybe that's related?
It is happening on iOS 13.3. It is not effecting my device, it is one of my users so I can not really test properly with Onion Browser etc.
It is happening on iOS 13.3. It is not effecting my device, it is one of my users so I can not really test properly with Onion Browser etc.
Meeh. Sorry, I'm running out of ideas.
I can confirm this crash is not replicated on latest Onion Browser with the same device. I will take a closer look. You can probably close this as it most likely my code that is the issue. When I find the issue I will share.
0.4.3.5 fixed it :) Thank you