Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Fixes the node start IPC connection #841

Merged
merged 6 commits into from
Jun 29, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ app.on('before-quit', function(event){

// delay quit, so the sockets can close
setTimeout(function(){
killedSockets = true;

ethereumNode.stop().then(function() {
killedSockets = true;
app.quit();
});
}, 500);
Expand Down
8 changes: 4 additions & 4 deletions modules/ethereumNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class EthereumNode extends EventEmitter {
return this._start(this.defaultNodeType, this.defaultNetwork)
.catch((err) => {
log.error('Failed to start node', err);

throw err;
});
});
Expand Down Expand Up @@ -289,8 +289,8 @@ class EthereumNode extends EventEmitter {
this._saveUserData('network', this._network);

return this._socket.connect({ path: ipcPath }, {
timeout: 30000 /* 30s */
})
timeout: 10000 /* 30s */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to increase this to 30s again after its fixed

})
.then(() => {
this.state = STATES.CONNECTED;
})
Expand Down Expand Up @@ -523,7 +523,7 @@ class EthereumNode extends EventEmitter {

resolve(proc);
}
}, 4000);
}, 1000);
})
});
});
Expand Down
27 changes: 21 additions & 6 deletions modules/sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Socket extends EventEmitter {

return this._resetSocket()
.then(() => {
let timeoutId = null;
let intervalId = null;
this._log.debug('Connecting...');

this._state = STATE.CONNECTING;
Expand All @@ -60,33 +62,45 @@ class Socket extends EventEmitter {
this._log.info('Connected!');

this._state = STATE.CONNECTED;
clearTimeout(timeoutId);
clearInterval(intervalId);

this.emit('connect');

resolve();
});

this._socket.once('error', (err) => {
if (STATE.CONNECTING === this._state) {
this._socket.on('error', (err) => {
// reject after the timeout is over
if (!options.timeout || STATE.CONNECTION_TIMEOUT === this._state) {
this._log.error('Connection error', err);

clearTimeout(timeoutId);
clearInterval(intervalId);

this._state = STATE.ERROR;

this._socket.removeAllListeners('error');
return reject(new Error(`Unable to connect to socket: ${err.message}`));
}
});

// add timeout
if (options.timeout) {
this._log.debug(`Will wait ${options.timeout}ms for connection to happen.`);

setTimeout(() => {
if (STATE.CONNECTING === this._state) {
this._socket.emit('error', `Connection timeout (took longer than ${options.timeout} ms)`);
timeoutId = setTimeout(() => {
if (STATE.CONNECTED !== this._state) {
this._state = STATE.CONNECTION_TIMEOUT;
// this._socket.emit('error', `Connection timeout (took longer than ${options.timeout} ms)`);
}
}, options.timeout);
}

this._socket.connect(connectConfig);
// try connecting
intervalId = setInterval(() => {
this._socket.connect(connectConfig);
}, 200);
});
});
}
Expand Down Expand Up @@ -388,6 +402,7 @@ const STATE = Socket.STATE = {
DISCONNECTED: 4,
ERROR: -1,
DISCONNECTION_TIMEOUT: -2,
CONNECTION_TIMEOUT: -3,
};


Expand Down
3 changes: 2 additions & 1 deletion modules/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@ class Windows {
alwaysOnTop: true,
resizable: false,
width: 100,
height: 50,
height: 80,
center: true,
frame: false,
useContentSize: true,
titleBarStyle: 'hidden', //hidden-inset: more space
skipTaskbar: true
},
});

Expand Down