Opened 21 months ago

Closed 3 months ago

Last modified 2 months ago

#20890 closed defect (fixed)

Increase connection timeout to avoid "Could not connect to Tor control port" errors

Reported by: torrc591 Owned by: brade
Priority: Medium Milestone:
Component: Applications/Tor Launcher Version:
Severity: Normal Keywords: TorBrowserTeam201805R, tbb-backported
Cc: mcs, tbb-team, torproject@… Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

I am on Windows 8.1 x64, not running an anti-virus app, or the firewall.
I have Tor 6.0.7
it was working fine, but something I have error "Could not connect to Tor control port"
Tried install new Tor in another folder and fine work, but after some time I get the same error message.
I tried
Start a Command Prompt (cmd.exe) and cd to Tor Browser\Browser (the folder that contains firefox.exe).
At the command prompt, type: firefox -console -jsconsole

And nothing. Nothing error logs, but Tor not running and I get same error message.

After shutdown system Tor fine work. But after some time, after close and reopen Tor window I get same error - "could not connect to Tor control port"

Child Tickets

Attachments (2)

TimeoutFailed.txt (4.8 KB) - added by GreenReaper 7 months ago.
Timeout failure
TimeoutOK.txt (8.2 KB) - added by GreenReaper 7 months ago.
Timeout OK (third time lucky)

Download all attachments as: .zip

Change History (17)

comment:1 Changed 21 months ago by cypherpunks

After shutdown system Tor fine work. But after some time, after close and reopen Tor window I get same error - "could not connect to Tor control port"

Check by task manager if tor.exe were terminated.

comment:2 Changed 14 months ago by TimeForGoToBed

I am having the same issue (or a closely related one). I see there are a number of tickets about this bug, but none of them provided any help for my situation. I am running Tor Browser 7.0.1 on Windows 7 Starter (which is 32-bit). I tried downgrading to 6.0.5, but that didn't help. Everything works fine on my Windows 7 Professional 64-bit system.

On my Windows 7 Starter system, Tor always works after a fresh install, but never works again after the first run. Rebooting does not help, in my case, only reinstalling (or deleting the install directory and then copying over a backup saved before the first run). This 32-bit system is a relatively slow netbook from a number of years ago, so it may be the hardcoded 30-second timeout that's causing it to get the Tor Launcher "Could not connect to Tor Control port." popup. It takes over 30 seconds on this system between launching the executable (on 2nd and subsequent runs) and the Tor Status window even appearing (and the progress bar never makes any progress before it fails). That timeout value should really be controllable via an extensions.torbutton.* preference and/or an environment variable. As with the OP, disabling Windows firewall and antivirus doesn't help. Also, hitting "Open Settings" after the failure popup results in a Tor Network Settings window that just displays a permanent "Waiting for Tor to start..." message. After a fresh install, that message only appears for a few seconds, and then after pressing "Connect", the connection bar generally starts making progress immediately.

Oddly, if I do a 'telnet localhost 9151' before (or after) the "Could not connect to Tor Control port." popup appears, I am able to successfully connect to the port (though I didn't try anything beyond connecting). I tried using the extensions.torlauncher.prompt_at_startup preference and also the TOR_FORCE_NET_CONFIG=1 environment variable to get it to start with the Tor Network Settings dialog after the first run, in the hopes that the explicit wait for Tor to start would work around the 30-second timeout, but strangely, in that situation, too, I just get a permanent "Waiting for Tor to start..." message. I also tried reverting a few different preferences / state files to their pre-first-run versions, but none of the ones I tried helped.

I have confirmed that tor.exe and firefox.exe are getting properly shut down between runs. My system clock is also set accurately. I have tried installing in multiple different (NTFS) locations, including the default of my Desktop, to rule out permissions issues. As with the OP, when I start the Tor Browser firefox.exe (I also have the normal Firefox on this system, and it works fine) with -console -jsconsole, I get no console output (do I need to change some log level to be more verbose or something?). There are a couple of add-ons I need to use with Tor Browser (they do not change my browser signature, and I believe their authors to be trustworthy), but since they require restarting to use, I can never use them, since I need to start with a fresh install every time. Note that selecting those for installation is not what's causing this failure, though -- it fails on the second run and thereafter regardless of whether I install any add-ons on the first run (and regardless of whether I make any settings changes). Though I've tried just about everything else, I have not attempted to run Tor Browser as an Administrator, so please let me know if trying that would help with debugging this.

Last edited 14 months ago by TimeForGoToBed (previous) (diff)

comment:3 Changed 14 months ago by gk

Status: newneeds_information

TimeForGoToBed thanks for this comment. Let's try to figure out what is going on in your case. I assume you are not getting any logs or notices that you can copy something to the clipboard? If that's the case then we might need to pursue a different road:

Could you download the expert bundle and replace the tor.exe that comes with Tor Browser with the one that's in the expert bundle? The location for the 0.3.0.8-based one is:

https://dist.torproject.org/torbrowser/7.0.1/tor-win32-0.3.0.8.zip
https://dist.torproject.org/torbrowser/7.0.1/tor-win32-0.3.0.8.zip.asc

You find the tor.exe in your Tor Browser in torbrowser_base_dir\Browser\TorBrowser\Tor. Starting with the tor.exe from the expert bundle should pop up a console with messages from tor. Could you do that before you first start a freshly installed Tor Browser so that we can compare both logs (please add them to this ticket), one you get from a working Tor Browser and one from a broken one.

comment:4 in reply to:  2 Changed 14 months ago by gk

Replying to TimeForGoToBed:

As with the OP, when I start the Tor Browser firefox.exe (I also have the normal Firefox on this system, and it works fine) with -console -jsconsole, I get no console output (do I need to change some log level to be more verbose or something?).

Yes. You need to set extensions.torlauncher.logmethod and extensions.torbutton.logmethod to 0 and ideally at least extensions.torlauncher.loglevel to 0 as well. You can do that in your about:config. If I (re)-start Tor Browser now on the command line with firefox.exe -console a console window pops up with Tor Launcher debug output. Please add that as well to this ticket.

Changed 7 months ago by GreenReaper

Attachment: TimeoutFailed.txt added

Timeout failure

Changed 7 months ago by GreenReaper

Attachment: TimeoutOK.txt added

Timeout OK (third time lucky)

comment:6 Changed 7 months ago by GreenReaper

Owner: changed from tbb-team to brade
Status: needs_informationassigned

The issue in my case is intermittent and subsequent launches may or may succeed. More often than not, they do not. Attached are logs from both cases.

When it fails, it does so on the third attempt to AUTHENTICATE (the first one seem to be refused quickly, while the second times out; the question is if that repeats):
TorLauncher NOTE: failed to open authenticated connection: [Exception... "Component returned failure code: 0x804b000e (NS_ERROR_NET_TIMEOUT) [nsIBinaryInputStream.readBytes]" nsresult: "0x804b000e (NS_ERROR_NET_TIMEOUT)"

I suspect seeds of this issue were introduced early on when a 15-second timeout was added:
https://gitweb.torproject.org/tor-launcher.git/commit/src/components/tl-protocol.js?id=bded277453e87892eca5a2834ecce079accf88a9

TorSendCommand tries a few times according to the code, but eventually it's game over. This is an issue for slow devices in general, but attempts to increase Tor security may also have increased its startup time.

My device is a Lenovo x120e with a 2011 dual-core mobile AMD Fusion CPU (E-350). It is entirely possible that insufficient time is being given for the launch, especially if other tasks are running in the background. A "good" launch is 30 seconds, and Tor.exe takes up the entirety of one core for at least 20 of those.

As for why it tends to work for the first launch, perhaps this is because according to
https://gitweb.torproject.org/tor-launcher.git/tree/src/components/tl-process.js
// Start tor with networking disabled if first run

Alternatively, maybe addons are installed or updated, or the necessary files are already in memory/cache, and not fragmented; or Tor has less state cached and so less to look up. I think you need to try running it in combination with other high-CPU tasks on a limited number of slow cores and see how it falls over.

I suspect #24776 is the same issue; Windows 7 Starter Edition is restricted to low-class devices.

comment:7 Changed 7 months ago by mcs

Cc: mcs tbb-team added

comment:8 Changed 3 months ago by TimeForGoToBed

Cc: torproject@… added

Howdy again. gk, my apologies for not getting back to you with the test results and logs you requested. I thought my Trac settings were going to cause me to be CC'd on this bug, but apparently not, so I'm just now seeing your replies. And then at some point my account apparently got auto-deleted, though it's allowed me to recreate it with the same name.

In any case, I didn't use my Windows 7 Starter system for a while, so unfortunately I don't know when this happened, but as of Browser 7.5.4, this bug no longer occurs for me. Everything connects up fine even on the 2nd and subsequent runs, and I no longer have to manually download browser updates, do them as a fresh install, and manually stage any XUL addons to be able to use them.

GreenReaper, who you callin' "low-class"? ;-) Yeah, definitely a lot more believable for it to've been a slow-system issue rather than a Windows-7-Starter-specific issue. I wonder if the fix was just to increase a timeout, or if some logic was changed.

Version 3, edited 3 months ago by TimeForGoToBed (previous) (next) (diff)

comment:9 Changed 3 months ago by TimeForGoToBed

GreenReaper, who you callin' "low-class"? ;-) Yeah, definitely a lot more believable for my flavor of the "Could not connector to Tor control port" failure to've been a general slow-system issue rather than a Windows-7-Starter-specific issue. I wonder if the fix was just to increase a timeout, or if some logic was changed.

comment:10 Changed 3 months ago by gk

Component: Applications/Tor BrowserApplications/Tor Launcher
Priority: Very HighMedium
Severity: CriticalNormal
Summary: Could not connect to Tor control portIncrease connection timeout to avoid "Could not connect to Tor control port" errors

Thanks for the reporting back. I think increasing the timeout to something that avoids this is not unreasonable. brade/mcs what do you think?

comment:11 Changed 3 months ago by mcs

Keywords: TorBrowserTeam201805R added
Status: assignedneeds_review

Kathy and I agree that it makes sense to increase the timeout. Here is a proposed fix:
https://gitweb.torproject.org/user/brade/tor-launcher.git/commit/?h=bug20890-01&id=9aa5fd46cb33528150400a9b94c14ad5e9b7d4ee

comment:12 Changed 3 months ago by gk

Keywords: tbb-backport added
Resolution: fixed
Status: needs_reviewclosed

Looks good and applied to master (commit 9aa5fd46cb33528150400a9b94c14ad5e9b7d4ee). Marking for possible backport for next stable release.

comment:13 Changed 3 months ago by TimeForGoToBed

Thanks, guys. Glad you erred on the side of caution and made the new timeout a full 5 minutes. As it turns out, I was premature in reporting that I was no longer experiencing the "Could not connect" issue. While it's no longer the case, as in older versions of Tor Browser, that it would never succeed in connecting to the control port after the first post-install run, I've found that if my netbook is running other applications, the "Could not connect" returns.

While experiencing the issue today, I tried various things that were unsuccessful in getting Tor Browser to successfully start up, including plugging into AC power to go to full-performance mode, switching from Wi-Fi to EtherNet, switching the priority of tor.exe and/or firefox.exe to High in the Task Manager just after startup, and even quitting all the other apps I was running. Only rebooting got Tor to work again. Intel, in their infinite wisdom, elected to limit my Atom CPU to being able to access 2 GB of RAM, so memory fragmentation and/or swapping may be responsible for the system being too slow to start up Tor within 30 seconds unless a reboot is done.

In any case, hope this does get backported to the next stable release; increasing the timeout seems like quite a safe change.

Last edited 3 months ago by TimeForGoToBed (previous) (diff)

comment:14 Changed 3 months ago by TimeForGoToBed

Oh, sorry, and meant to also mention that indeed, when this happens, there is nothing in the log. The first time it happens, it gives you the option to copy the log messages to the clipboard, but those messages are just the ones that went to the log the last time you connected successfully. After that, you no longer are given the option to copy log messages, until after the next time you succeed in running Tor Browser again.

comment:15 Changed 2 months ago by gk

Keywords: tbb-backported added; tbb-backport removed

Backported to maint-0.2.14 with commit f34e4cc7047a752f4c33736924b2133b371829b8.

Note: See TracTickets for help on using tickets.