Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Out of paranoia, check we're closing the right control channel.
Browse files Browse the repository at this point in the history
  • Loading branch information
riastradh-brave committed Jul 10, 2018
1 parent e680e1c commit 0899642
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions app/tor.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,10 @@ class TorDaemon extends EventEmitter {

const readable = controlSocket
const writable = controlSocket
this._control = new TorControl(readable, writable)
this._control.on('error', (err) => this._controlError(err))
this._control.on('close', () => this._controlClosed())
const control = new TorControl(readable, writable)
this._control = control
this._control.on('error', (err) => this._controlError(control, err))
this._control.on('close', () => this._controlClosed(control))

// We have finished polling, _and_ we are scheduled to be
// notified either by (a) our file system activity watcher, or
Expand Down Expand Up @@ -538,12 +539,17 @@ class TorDaemon extends EventEmitter {
* socket. Report it to the console and give up by destroying the
* control connection.
*
* @param {TorControl} control
* @param {Error} err
*/
_controlError (err) {
assert(this._control)
_controlError (control, err) {
if (this._control === control) {
this._control = null
} else {
console.log('tor: control error got deferred')
}
console.log(`tor: control socket error: ${err}`)
this._control.destroy(err)
control.destroy(err)
}

/*
Expand All @@ -552,10 +558,15 @@ class TorDaemon extends EventEmitter {
* has exited.
*
* TODO(riastradh): Also try to restart tor or anything?
*
* @param {TorControl} control
*/
_controlClosed () {
assert(this._control)
this._control = null
_controlClosed (control) {
if (this._control === control) {
this._control = null
} else {
console.log('tor: control closure got deferred')
}
// Assume this means the process exited.
this.emit('exit')
// Poll in case we received a watch event for file system activity
Expand Down

0 comments on commit 0899642

Please sign in to comment.