talmobi/tor-request

Unable to connect to Tor Socket (Error: Socket Closed)

kaue opened this issue · 5 comments

kaue commented
May 09 13:49:21.000 [notice] Tor 0.2.6.10 (git-58c51dc6087b0936) opening log file.
May 09 13:49:21.028 [notice] Tor v0.2.6.10 (git-58c51dc6087b0936) running on Linux with Libevent 1.4.13-stable, OpenSSL 1.0.1e-fips and Zlib 1.2.3.
May 09 13:49:21.028 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
May 09 13:49:21.028 [notice] Read configuration file "/tor/etc/tor/torrc".
May 09 13:49:21.031 [notice] Opening Socks listener on 127.10.254.1:9050
May 09 13:49:21.000 [notice] Parsing GEOIP IPv4 file /tor/share/tor/geoip.
May 09 13:49:21.000 [notice] Parsing GEOIP IPv6 file /tor/share/tor/geoip6.
May 09 13:49:21.000 [notice] We were built to run on a 64-bit CPU, with OpenSSL 1.0.1 or later, but with a version of OpenSSL that apparently lacks accelerated support for the NIST P-224 and P-256 groups. Building openssl with such support (using the enable-ec_nistp_64_gcc_128 option when configuring it) would make ECDH much faster.
May 09 13:49:21.000 [notice] Bootstrapped 0%: Starting
May 09 13:49:21.000 [notice] Bootstrapped 5%: Connecting to directory server
May 09 13:49:21.000 [notice] Bootstrapped 80%: Connecting to the Tor network
May 09 13:49:21.000 [notice] Bootstrapped 85%: Finishing handshake with first hop
May 09 13:49:22.000 [notice] Bootstrapped 90%: Establishing a Tor circuit
May 09 13:49:23.000 [notice] Tor has successfully opened a circuit. Looks like client functionality is working.
May 09 13:49:23.000 [notice] Bootstrapped 100%: Done
var tr = require('tor-request');
tr.setTorAddress('127.10.254.1', 9050);

tr.request('https://api.ipify.org', function (err, res, body) {
  if(err) console.log(err);
  if (!err && res.statusCode == 200) {
    console.log("Your public (through Tor) IP is: " + body);
  }
});

Result:

Error: Socket Closed
    at Socket.<anonymous> (/node_modules/socks/lib/socks-client.js:61:20)
    at Object.onceWrapper (events.js:293:19)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at TCP._handle.close [as _onclose] (net.js:511:12)
kaue commented

I was able to fix the issue changing the SocksPort var on etc/tor/torrc to 127.10.254.1:auto.

Hmm, so this was not an issue with tor-request but rather tor's own configuration?

Thanks for the explanation and solution -- could perhaps add a heads-up to the README or something for common issues like these.

I forgot the start. I tried to delete the comment but you have been too fast, sorry. Thx

@kaue I got this error after Tor exited suddenly. A restart made it work again