From 5be97109a62f41f9e017b35d9ae286864c9fe7df Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 28 May 2018 11:29:42 +0200 Subject: [PATCH 1/3] Fix bug .id of undefined (from thibaut) --- electron/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/electron/index.js b/electron/index.js index d61a7aa1..8ee41865 100644 --- a/electron/index.js +++ b/electron/index.js @@ -60,6 +60,11 @@ function createWindow () { urls: ['ws://*/*', 'wss://*/*'] }, (details, callback) => { + if (!mainWindow) { + // There might be a split second where the user closes the app, so + // mainWindow is null, but there is still a network request done. + return; + } details.requestHeaders.Origin = `parity://${mainWindow.id}.ui.parity`; callback({ requestHeaders: details.requestHeaders }); // eslint-disable-line } -- GitLab From 1bdae1875b928da68c73ea0e3fed6958545e2382 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 28 May 2018 12:31:15 +0200 Subject: [PATCH 2/3] Remove ps-node and ping node for isParityRunning --- electron/operations/isParityRunning.js | 58 ++++++++++++++------------ package.json | 1 - yarn.lock | 16 ------- 3 files changed, 31 insertions(+), 44 deletions(-) diff --git a/electron/operations/isParityRunning.js b/electron/operations/isParityRunning.js index b032d3e8..2b436c54 100644 --- a/electron/operations/isParityRunning.js +++ b/electron/operations/isParityRunning.js @@ -3,42 +3,46 @@ // // SPDX-License-Identifier: MIT -const { promisify } = require('util'); +const axios = require('axios'); +const retry = require('async-retry'); + +const cli = require('../cli'); const pino = require('../utils/pino')(); -const ps = require('ps-node'); -const lookup = promisify(ps.lookup); +// Try to ping these hosts +const hostsToPing = ['http://127.0.0.1:8545', 'http://127.0.0.1:8546']; +if (cli.wsInterface || cli.wsPort) { + // Also try custom host/port if a --ws-interface or --ws-port flag is passed + hostsToPing.push( + `http://${cli.wsInterface || '127.0.0.1'}:${cli.wsPort || '8545'}` + ); +} /** - * Detect if another instance of parity is already running or not. + * Detect if another instance of parity is already running or not. To achieve + * that, we just ping on the common hosts, see hostsToPing array. * - * @return [Object | Boolean] - If there is another instance, return the - * instance object. If not return false. - * @example Here is what's returned when there is an instance running - * { - * pid: '14885', - * command: '/Users/amaurymartiny/Workspace/parity/target/release/parity', - * arguments: [ - * '--testnet', - * '--no-periodic-snapshot', - * '--ws-origins', - * 'all', - * '--light' - * ], - * ppid: '14879' - * } + * @return [Promise] - Promise that resolves to true or false. */ - const isParityRunning = async () => { - const results = await lookup({ command: 'parity' }); - if (results && results.length) { - pino.info( - `Another instance of parity is already running with pid ${results[0] - .pid}, skip running local instance.` + try { + // Retry to ping as many times as there are hosts in `hostsToPing` + await retry( + async (_, attempt) => { + await axios.get(hostsToPing[attempt - 1]); + pino.info( + `Another instance of parity is already running on ${hostsToPing[ + attempt - 1 + ]}, skip running local instance.` + ); + }, + { retries: hostsToPing.length } ); - return results[0]; + + return true; + } catch (e) { + return false; } - return false; }; module.exports = isParityRunning; diff --git a/package.json b/package.json index c5a609a8..92579d96 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,6 @@ "pino": "^4.16.1", "pino-multi-stream": "^3.1.2", "promise-any": "^0.2.0", - "ps-node": "^0.1.6", "react": "^16.3.2", "react-blockies": "^1.3.0", "react-dom": "^16.3.2", diff --git a/yarn.lock b/yarn.lock index 22be0b7f..d86a819c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2147,10 +2147,6 @@ connect-history-api-fallback@^1.3.0: version "1.5.0" resolved "https://registry.yarnpkg.com/connect-history-api-fallback/-/connect-history-api-fallback-1.5.0.tgz#b06873934bc5e344fef611a196a6faae0aee015a" -connected-domain@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/connected-domain/-/connected-domain-1.0.0.tgz#bfe77238c74be453a79f0cb6058deeb4f2358e93" - console-browserify@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/console-browserify/-/console-browserify-1.1.0.tgz#f0241c45730a9fc6323b206dbf38edc741d0bb10" @@ -7278,12 +7274,6 @@ prr@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476" -ps-node@^0.1.6: - version "0.1.6" - resolved "https://registry.yarnpkg.com/ps-node/-/ps-node-0.1.6.tgz#9af67a99d7b1d0132e51a503099d38a8d2ace2c3" - dependencies: - table-parser "^0.1.3" - ps-tree@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/ps-tree/-/ps-tree-1.1.0.tgz#b421b24140d6203f1ed3c76996b4427b08e8c014" @@ -8835,12 +8825,6 @@ symbol-tree@^3.2.1: version "3.2.2" resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6" -table-parser@^0.1.3: - version "0.1.3" - resolved "https://registry.yarnpkg.com/table-parser/-/table-parser-0.1.3.tgz#0441cfce16a59481684c27d1b5a67ff15a43c7b0" - dependencies: - connected-domain "^1.0.0" - table@4.0.2: version "4.0.2" resolved "https://registry.yarnpkg.com/table/-/table-4.0.2.tgz#a33447375391e766ad34d3486e6e2aedc84d2e36" -- GitLab From 212657a8bbb7df4012bbecca388f6403d8852a54 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 28 May 2018 12:59:14 +0200 Subject: [PATCH 3/3] Small tweaks --- electron/operations/isParityRunning.js | 9 ++++----- electron/operations/runParity.js | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/electron/operations/isParityRunning.js b/electron/operations/isParityRunning.js index 2b436c54..fbb3ca34 100644 --- a/electron/operations/isParityRunning.js +++ b/electron/operations/isParityRunning.js @@ -6,7 +6,7 @@ const axios = require('axios'); const retry = require('async-retry'); -const cli = require('../cli'); +const { cli } = require('../cli'); const pino = require('../utils/pino')(); // Try to ping these hosts @@ -29,11 +29,10 @@ const isParityRunning = async () => { // Retry to ping as many times as there are hosts in `hostsToPing` await retry( async (_, attempt) => { - await axios.get(hostsToPing[attempt - 1]); + const host = hostsToPing[attempt - 1]; // Attempt starts with 1 + await axios.get(host); pino.info( - `Another instance of parity is already running on ${hostsToPing[ - attempt - 1 - ]}, skip running local instance.` + `Another instance of parity is already running on ${host}, skip running local instance.` ); }, { retries: hostsToPing.length } diff --git a/electron/operations/runParity.js b/electron/operations/runParity.js index aef9b907..cfe211e3 100644 --- a/electron/operations/runParity.js +++ b/electron/operations/runParity.js @@ -23,7 +23,7 @@ let parity = null; // Will hold the running parity instance // panic). They happen when an instance of parity is already running, and // parity-ui tries to launch another one. const catchableErrors = [ - 'is already in use, make sure that another instance of an Ethereum client is not running or change the address using the --ws-port and --ws-interface options.', + 'is already in use, make sure that another instance of an Ethereum client is not running', 'IO error: While lock file:' ]; -- GitLab