Tor fails to start if previous Tor instance is still running
I ran into this issue a couple of times while debugging #1293 (closed), and now I've seen it in a user feedback log (also affected by #1293 (closed), as far as I can tell).
05-25 14:25:08.926 I/TorPlugin: May 25 16:25:08.926 [notice] Tor 0.2.9.14 (git-73e1a45b461ab669) running on Linux with Libevent 2.0.22-stable, OpenSSL 1.0.2n and Zlib 1.2.8.
05-25 14:25:08.939 I/TorPlugin: May 25 16:25:08.927 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
05-25 14:25:08.939 I/TorPlugin: May 25 16:25:08.927 [notice] Read configuration file "/data/data/org.briarproject.briar.android/app_tor/torrc".
05-25 14:25:08.939 I/TorPlugin: May 25 16:25:08.935 [notice] Opening Control listener on 127.0.0.1:59051
05-25 14:25:08.939 I/TorPlugin: May 25 16:25:08.935 [warn] Could not bind to 127.0.0.1:59051: Address already in use. Is Tor already running?
05-25 14:25:08.940 I/TorPlugin: May 25 16:25:08.935 [warn] Failed to parse/validate config: Failed to bind one of the listener ports.
05-25 14:25:08.940 I/TorPlugin: May 25 16:25:08.935 [err] Reading config failed--see warnings above.
05-25 14:25:08.940 W/TorPlugin: Tor exited with value 1
The problem occurs because the previous Tor instance is still using the control port. This is unlikely to happen if Tor starts and stops normally, because the shutdown command takes effect very quickly. But if Briar fails to open the control connection (e.g. due to #1293 (closed) or similar bugs), Tor won't exit until a short time after Briar exits, during which time Briar may have been relaunched. I think this could also happen if Briar crashes and is immediately relaunched.