iCepa / Tor.framework

Tor framework for the iCepa project
Other
245 stars 53 forks source link

TorThread is never deallocated #86

Closed TruszczynskiA closed 11 months ago

TruszczynskiA commented 11 months ago

I've noticed that TorThread is never deallocated and stays active even after the cancel() method is called and all references to that object are removed. This situation makes it impossible to create a new thread with a different TorConfiguration because there can be only one "active" Tor thread.

How to reproduce issue:


    var thread: TorThread?

    func testTor() {
        Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
            print("[Test] is TorThread active: \(TorThread.active != nil)")
        }

        DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { [weak self] in
            print("[Test] Start")
            let thread = TorThread()
            thread.start()
            self?.thread = thread
        }

        DispatchQueue.main.asyncAfter(deadline: .now() + 6.0) { [weak self] in
            print("[Test] Stop")
            self?.thread?.cancel()
            self?.thread = nil
        }
    }

Result:

[Test] is TorThread active: false
[Test] is TorThread active: false
[Test] is TorThread active: false
[Test] Start
[Test] is TorThread active: true
[Test] is TorThread active: true
[Test] is TorThread active: true
[Test] Stop
[Test] is TorThread active: true
[Test] is TorThread active: true
[Test] is TorThread active: true
[Test] is TorThread active: true
[Test] is TorThread active: true
tladesignz commented 11 months ago

Yeah. This is, because Tor is not really used to run in a thread, esp. not in an Cocoa Thread.

You will need to connect the TorController first and then disconnect that, as the disconnect will issue a shutdown command to Tor.

HtH

TruszczynskiA commented 11 months ago

Hi, I've added a controller, but I don't see any difference. The thread is still retained by the framework after the app called controller.disconnect().

Code:

func testTor() {

        setupLogger()

        do {
            try createDataDirectoryIfNeeded()
            try createAuthDirectoryIfNeeded()
        } catch {
            print("[Test] Error: \(error)")
        }

        Task {
            try? await Task.sleep(for: .seconds(3))
            createThread()
            createController()
            await connectController()
            try? await Task.sleep(for: .seconds(3))
            disconnectController()
        }
    }

    private func createDataDirectoryIfNeeded() throws {
        guard !FileManager.default.fileExists(atPath: dataDirectoryUrl.path) else { return }
        try FileManager.default.createDirectory(at: dataDirectoryUrl, withIntermediateDirectories: true)
    }

    private func createAuthDirectoryIfNeeded() throws {
        guard !FileManager.default.fileExists(atPath: authDirectoryURL.path) else { return }
        try FileManager.default.createDirectory(at: authDirectoryURL, withIntermediateDirectories: true)
    }

    private func createThread() {
        let configuration = self.makeTorConfiguration()
        let thread = TorThread(configuration: configuration)
        thread.start()
        print("[Test] Thread created")
    }

    private func createController() {
        let controller = TorController(socketHost: controlAddress, port: controlPort)
        self.controller = controller
        print("[Test] Controller created")
    }

    private func connectController(retryCount: Int = 0) async {

        guard let controller else { return }

        do {
            try controller.connect()
            print("[Test] Controller connected. Retry count: \(retryCount)")
        } catch {
            print("[Test] Unable to connect: \(error)")
            try? await Task.sleep(for: .seconds(1))
            await connectController(retryCount: retryCount + 1)
        }
    }

    private func disconnectController() {
        controller?.disconnect()
        print("[Test] Controller disconnected")
    }

    private func setupLogger() {
        Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
            print("[Test] is TorThread active: \(TorThread.active != nil)")
        }
    }

    private func makeTorConfiguration() -> TorConfiguration {
        let configuration = TorConfiguration()
        configuration.cookieAuthentication = true
        configuration.dataDirectory = URL(fileURLWithPath: NSTemporaryDirectory())
        configuration.arguments = makeBaseArguments()

        return configuration
    }

    private func makeBaseArguments() -> [String] {
        [
            "--allow-missing-torrc",
            "--ignore-missing-torrc",
            "--clientonly", "1",
            "--AvoidDiskWrites", "1",
            "--socksport", "39059",
            "--controlport", "\(controlAddress):\(controlPort)",
            "--log", "notice stdout",
            "--clientuseipv6", "1",
            "--ClientTransportPlugin", "obfs4 socks5 127.0.0.1:47351",
            "--ClientTransportPlugin", "meek_lite socks5 127.0.0.1:47352",
            "--ClientOnionAuthDir", authDirectoryURL.path
        ]
    }

Result:

[Test] is TorThread active: false
[Test] is TorThread active: false
[Test] is TorThread active: false
[Test] Thread created
[Test] Controller created
[Test] Unable to connect: Error Domain=NSPOSIXErrorDomain Code=61 "Connection refused"
[Test] is TorThread active: true
[Test] Controller connected. Retry count: 1
[Test] is TorThread active: true
[Test] is TorThread active: true
[Test] is TorThread active: true
[Test] Controller disconnected
[Test] is TorThread active: true
[Test] is TorThread active: true
[Test] is TorThread active: true
[Test] is TorThread active: true
[Test] is TorThread active: true

Logs:

Oct 12 14:10:17.656 [notice] Tor 0.4.8.4 running on Darwin with Libevent 2.1.12-stable, OpenSSL 3.1.2, Zlib 1.2.12, Liblzma 5.4.4, Libzstd N/A and Unknown N/A as libc.
Oct 12 14:10:17.656 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://support.torproject.org/faq/staying-anonymous/
Oct 12 14:10:17.656 [notice] Configuration file "/Users/browncoat/Library/Developer/CoreSimulator/Devices/CFE35A9B-FFBA-4C03-BBB5-BD9DC7D3B5EA/data/Containers/Data/Application/02B02AD1-2CAC-47D0-A409-2D7C4D7367E7/.torrc" not present, using reasonable defaults.
Oct 12 14:10:17.658 [notice] Opening Socks listener on 127.0.0.1:39059
Oct 12 14:10:17.659 [notice] Opened Socks listener connection (ready) on 127.0.0.1:39059
Oct 12 14:10:17.659 [notice] Opening Control listener on 127.0.0.1:39069
Oct 12 14:10:17.659 [notice] Opened Control listener connection (ready) on 127.0.0.1:39069
Oct 12 14:10:18.000 [notice] Bootstrapped 0% (starting): Starting
Oct 12 14:10:30.000 [notice] Starting with guard context "default"
Oct 12 14:10:30.000 [warn] tor_bug_occurred_: Bug: ./src/feature/relay/routerkeys.h:56: relay_key_is_unavailable_: This line should not have been reached. (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug: Tor 0.4.8.4: Line unexpectedly reached at relay_key_is_unavailable_ at ./src/feature/relay/routerkeys.h:56. Stack trace: (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     0   Tor                                 0x0000000104b68d78 log_backtrace_impl + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     1   Tor                                 0x0000000104b7646c tor_bug_occurred_ + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     2   Tor                                 0x0000000104b066c4 server_onion_keys_new + 64 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     3   Tor                                 0x0000000104aa8ac8 worker_state_new + 48 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     4   Tor                                 0x0000000104b6d034 threadpool_new + 256 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     5   Tor                                 0x0000000104aa8a00 cpuworker_init + 128 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     6   Tor                                 0x0000000104ae65ac run_tor_main_loop + 200 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     7   Tor                                 0x0000000104ae68a4 tor_run_main + 312 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     8   Tor                                 0x00000001046598ec -[TORThread main] + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     9   Foundation                          0x0000000180dd627c __NSThread__start__ + 720 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     10  libsystem_pthread.dylib             0x0000000102bef4c0 _pthread_start + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     11  libsystem_pthread.dylib             0x0000000102bea6f0 thread_start + 8 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] tor_bug_occurred_: Bug: ./src/feature/relay/routerkeys.h:56: relay_key_is_unavailable_: This line should not have been reached. (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug: Tor 0.4.8.4: Line unexpectedly reached at relay_key_is_unavailable_ at ./src/feature/relay/routerkeys.h:56. Stack trace: (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     0   Tor                                 0x0000000104b68d78 log_backtrace_impl + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     1   Tor                                 0x0000000104b7646c tor_bug_occurred_ + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     2   Tor                                 0x0000000104b066c4 server_onion_keys_new + 64 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     3   Tor                                 0x0000000104aa8ac8 worker_state_new + 48 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     4   Tor                                 0x0000000104b6d034 threadpool_new + 256 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     5   Tor                                 0x0000000104aa8a00 cpuworker_init + 128 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     6   Tor                                 0x0000000104ae65ac run_tor_main_loop + 200 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     7   Tor                                 0x0000000104ae68a4 tor_run_main + 312 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     8   Tor                                 0x00000001046598ec -[TORThread main] + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     9   Foundation                          0x0000000180dd627c __NSThread__start__ + 720 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     10  libsystem_pthread.dylib             0x0000000102bef4c0 _pthread_start + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     11  libsystem_pthread.dylib             0x0000000102bea6f0 thread_start + 8 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] tor_bug_occurred_: Bug: ./src/feature/relay/routerkeys.h:56: relay_key_is_unavailable_: This line should not have been reached. (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug: Tor 0.4.8.4: Line unexpectedly reached at relay_key_is_unavailable_ at ./src/feature/relay/routerkeys.h:56. Stack trace: (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     0   Tor                                 0x0000000104b68d78 log_backtrace_impl + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     1   Tor                                 0x0000000104b7646c tor_bug_occurred_ + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     2   Tor                                 0x0000000104b066c4 server_onion_keys_new + 64 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     3   Tor                                 0x0000000104aa8ac8 worker_state_new + 48 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     4   Tor                                 0x0000000104b6d034 threadpool_new + 256 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     5   Tor                                 0x0000000104aa8a00 cpuworker_init + 128 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     6   Tor                                 0x0000000104ae65ac run_tor_main_loop + 200 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     7   Tor                                 0x0000000104ae68a4 tor_run_main + 312 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     8   Tor                                 0x00000001046598ec -[TORThread main] + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     9   Foundation                          0x0000000180dd627c __NSThread__start__ + 720 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     10  libsystem_pthread.dylib             0x0000000102bef4c0 _pthread_start + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     11  libsystem_pthread.dylib             0x0000000102bea6f0 thread_start + 8 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] tor_bug_occurred_: Bug: ./src/feature/relay/routerkeys.h:56: relay_key_is_unavailable_: This line should not have been reached. (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug: Tor 0.4.8.4: Line unexpectedly reached at relay_key_is_unavailable_ at ./src/feature/relay/routerkeys.h:56. Stack trace: (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     0   Tor                                 0x0000000104b68d78 log_backtrace_impl + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     1   Tor                                 0x0000000104b7646c tor_bug_occurred_ + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     2   Tor                                 0x0000000104b066c4 server_onion_keys_new + 64 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     3   Tor                                 0x0000000104aa8ac8 worker_state_new + 48 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     4   Tor                                 0x0000000104b6d034 threadpool_new + 256 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     5   Tor                                 0x0000000104aa8a00 cpuworker_init + 128 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     6   Tor                                 0x0000000104ae65ac run_tor_main_loop + 200 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     7   Tor                                 0x0000000104ae68a4 tor_run_main + 312 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     8   Tor                                 0x00000001046598ec -[TORThread main] + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     9   Foundation                          0x0000000180dd627c __NSThread__start__ + 720 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     10  libsystem_pthread.dylib             0x0000000102bef4c0 _pthread_start + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     11  libsystem_pthread.dylib             0x0000000102bea6f0 thread_start + 8 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] tor_bug_occurred_: Bug: ./src/feature/relay/routerkeys.h:56: relay_key_is_unavailable_: This line should not have been reached. (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug: Tor 0.4.8.4: Line unexpectedly reached at relay_key_is_unavailable_ at ./src/feature/relay/routerkeys.h:56. Stack trace: (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     0   Tor                                 0x0000000104b68d78 log_backtrace_impl + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     1   Tor                                 0x0000000104b7646c tor_bug_occurred_ + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     2   Tor                                 0x0000000104b066c4 server_onion_keys_new + 64 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     3   Tor                                 0x0000000104aa8ac8 worker_state_new + 48 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     4   Tor                                 0x0000000104b6d034 threadpool_new + 256 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     5   Tor                                 0x0000000104aa8a00 cpuworker_init + 128 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     6   Tor                                 0x0000000104ae65ac run_tor_main_loop + 200 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     7   Tor                                 0x0000000104ae68a4 tor_run_main + 312 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     8   Tor                                 0x00000001046598ec -[TORThread main] + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     9   Foundation                          0x0000000180dd627c __NSThread__start__ + 720 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     10  libsystem_pthread.dylib             0x0000000102bef4c0 _pthread_start + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     11  libsystem_pthread.dylib             0x0000000102bea6f0 thread_start + 8 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] tor_bug_occurred_: Bug: ./src/feature/relay/routerkeys.h:56: relay_key_is_unavailable_: This line should not have been reached. (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug: Tor 0.4.8.4: Line unexpectedly reached at relay_key_is_unavailable_ at ./src/feature/relay/routerkeys.h:56. Stack trace: (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     0   Tor                                 0x0000000104b68d78 log_backtrace_impl + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     1   Tor                                 0x0000000104b7646c tor_bug_occurred_ + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     2   Tor                                 0x0000000104b066c4 server_onion_keys_new + 64 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     3   Tor                                 0x0000000104aa8ac8 worker_state_new + 48 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     4   Tor                                 0x0000000104b6d034 threadpool_new + 256 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     5   Tor                                 0x0000000104aa8a00 cpuworker_init + 128 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     6   Tor                                 0x0000000104ae65ac run_tor_main_loop + 200 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     7   Tor                                 0x0000000104ae68a4 tor_run_main + 312 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     8   Tor                                 0x00000001046598ec -[TORThread main] + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     9   Foundation                          0x0000000180dd627c __NSThread__start__ + 720 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     10  libsystem_pthread.dylib             0x0000000102bef4c0 _pthread_start + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     11  libsystem_pthread.dylib             0x0000000102bea6f0 thread_start + 8 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] tor_bug_occurred_: Bug: ./src/feature/relay/routerkeys.h:56: relay_key_is_unavailable_: This line should not have been reached. (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug: Tor 0.4.8.4: Line unexpectedly reached at relay_key_is_unavailable_ at ./src/feature/relay/routerkeys.h:56. Stack trace: (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     0   Tor                                 0x0000000104b68d78 log_backtrace_impl + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     1   Tor                                 0x0000000104b7646c tor_bug_occurred_ + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     2   Tor                                 0x0000000104b066c4 server_onion_keys_new + 64 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     3   Tor                                 0x0000000104aa8ac8 worker_state_new + 48 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     4   Tor                                 0x0000000104b6d034 threadpool_new + 256 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     5   Tor                                 0x0000000104aa8a00 cpuworker_init + 128 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     6   Tor                                 0x0000000104ae65ac run_tor_main_loop + 200 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     7   Tor                                 0x0000000104ae68a4 tor_run_main + 312 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     8   Tor                                 0x00000001046598ec -[TORThread main] + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     9   Foundation                          0x0000000180dd627c __NSThread__start__ + 720 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     10  libsystem_pthread.dylib             0x0000000102bef4c0 _pthread_start + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     11  libsystem_pthread.dylib             0x0000000102bea6f0 thread_start + 8 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] tor_bug_occurred_: Bug: ./src/feature/relay/routerkeys.h:56: relay_key_is_unavailable_: This line should not have been reached. (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug: Tor 0.4.8.4: Line unexpectedly reached at relay_key_is_unavailable_ at ./src/feature/relay/routerkeys.h:56. Stack trace: (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     0   Tor                                 0x0000000104b68d78 log_backtrace_impl + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     1   Tor                                 0x0000000104b7646c tor_bug_occurred_ + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     2   Tor                                 0x0000000104b066c4 server_onion_keys_new + 64 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     3   Tor                                 0x0000000104aa8ac8 worker_state_new + 48 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     4   Tor                                 0x0000000104b6d034 threadpool_new + 256 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     5   Tor                                 0x0000000104aa8a00 cpuworker_init + 128 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     6   Tor                                 0x0000000104ae65ac run_tor_main_loop + 200 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     7   Tor                                 0x0000000104ae68a4 tor_run_main + 312 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     8   Tor                                 0x00000001046598ec -[TORThread main] + 324 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     9   Foundation                          0x0000000180dd627c __NSThread__start__ + 720 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     10  libsystem_pthread.dylib             0x0000000102bef4c0 _pthread_start + 104 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [warn] Bug:     11  libsystem_pthread.dylib             0x0000000102bea6f0 thread_start + 8 (on Tor 0.4.8.4 )
Oct 12 14:10:30.000 [notice] New control connection opened from 127.0.0.1.
Oct 12 14:10:31.000 [notice] Bootstrapped 5% (conn): Connecting to a relay
Oct 12 14:10:31.000 [notice] Bootstrapped 10% (conn_done): Connected to a relay
Oct 12 14:10:31.000 [notice] Bootstrapped 14% (handshake): Handshaking with a relay
Oct 12 14:10:31.000 [notice] Bootstrapped 15% (handshake_done): Handshake with a relay done
Oct 12 14:10:31.000 [notice] Bootstrapped 75% (enough_dirinfo): Loaded enough directory info to build circuits
Oct 12 14:10:31.000 [notice] Bootstrapped 90% (ap_handshake_done): Handshake finished with a relay to build circuits
Oct 12 14:10:31.000 [notice] Bootstrapped 95% (circuit_create): Establishing a Tor circuit
Oct 12 14:10:32.000 [notice] Bootstrapped 100% (done): Done
tladesignz commented 11 months ago

AFAIR, you cannot stop Tor reliably until it's finished bootstrapping. Try disconnect it after you received the established signal.

Here's an example of how that should look like: https://github.com/guardianproject/orbot-apple/blob/89e99a93818a48e6cea14d0f3a5c18f0be6b11f5/Shared/TorManager.swift#L219