Mowje / node-ths

Node.js module to create tor hidden services and manage them programmatically
MIT License
36 stars 8 forks source link

No exception thrown if tor port binding fails. #6

Open mattcollier opened 9 years ago

mattcollier commented 9 years ago

if one executes two instances of the following code:

var dataDir = __dirname + '/demo-data';
var thsBuilder = require('ths');
var ths = new thsBuilder(dataDir);

ths.start(false, function() {
  console.log('ths has started.');
});

The second instance fails without any error or exception. By enabling some logging on line 396:

console.log('[tor Process] ', data.toString('utf8')); 

I can see the cause of the issue:

[tor Process]  Mar 24 09:44:30.437 [notice] Tor v0.2.5.10 (git-43a5f3d91e726291) running on Linux with Libevent 2.0.21-stable, OpenSSL 1.0.1k and Zlib 1.2.8.
Mar 24 09:44:30.437 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Mar 24 09:44:30.437 [notice] Read configuration file "/home/matt/thstiming/demo-data/ths-data/torrc".
[tor Process]  Mar 24 09:44:30.441 [notice] Opening Socks listener on 127.0.0.1:9999
Mar 24 09:44:30.441 [warn] Could not bind to 127.0.0.1:9999: Address already in use. Is Tor already running?
Mar 24 09:44:30.441 [notice] Opening Control listener on 127.0.0.1:9998
Mar 24 09:44:30.441 [warn] Could not bind to 127.0.0.1:9998: Address already in use. Is Tor already running?
Mar 24 09:44:30.441 [warn] Failed to parse/validate config: Failed to bind one of the listener ports.
Mar 24 09:44:30.441 [err] Reading config failed--see warnings above.

During development, I have encountered zombie tor processes which cause unexpected behavior. Catching this type of error would be helpful.

abenmrad commented 9 years ago

[In dev branch] Added a bindingError event, that receives the error that cannot be bound.