Skip to content

Commit

Permalink
Splash screen msg on port conflict (#463)
Browse files Browse the repository at this point in the history
- Handle error for EADDRINUSE and replaced with message including ip and port
- Remove dependency `tcp-port-used`
- Re-order checks in ProtectedRoute to allow opening settings when no wallets exist
- Remove unused imports
  • Loading branch information
rithvikvibhu authored May 4, 2022
1 parent af524be commit 34d6ea7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
38 changes: 12 additions & 26 deletions app/background/node/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { VALID_NETWORKS } from '../../constants/networks';
import path from 'path';
import fs from 'fs';
import crypto from 'crypto';
import tcpPortUsed from 'tcp-port-used';
import EventEmitter from 'events';
import { NodeClient } from 'hs-client';
import { BigNumber } from 'bignumber.js';
Expand Down Expand Up @@ -133,7 +132,18 @@ export class NodeService extends EventEmitter {

switch (conn.type) {
case ConnectionTypes.P2P:
await this.startNode();
try {
await this.startNode();
} catch (error) {
if (error.code === 'EADDRINUSE') {
throw new Error(`
Could not bind to ${error.address}:${error.port}.
Please make sure no other hsd or Bob Wallet instance is running.
Quit Bob, and try again.`);
} else {
throw error;
}
}
await this.setHSDLocalClient();
dispatchToMainWindow({
type: SET_CUSTOM_RPC_STATUS,
Expand Down Expand Up @@ -190,12 +200,6 @@ export class NodeService extends EventEmitter {
return;
}

const portsFree = await checkHSDPortsFree(this.network);

if (!portsFree) {
throw new Error('hsd ports in use. Please make sure no other hsd instance is running, quit Bob, and try again.');
}

console.log(`Starting node on ${this.networkName} network.`);

const dir = await this.getDir();
Expand Down Expand Up @@ -576,24 +580,6 @@ export class NodeService extends EventEmitter {
}
}

async function checkHSDPortsFree(network) {
const ports = [
network.port,
network.rpcPort,
// network.walletPort,
network.nsPort,
];

for (const port of ports) {
const inUse = await tcpPortUsed.check(port);
if (inUse) {
return false;
}
}

return true;
}

export const service = new NodeService();

const sName = 'Node';
Expand Down
2 changes: 2 additions & 0 deletions app/ducks/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SET_FEE_INFO,
SET_CUSTOM_RPC_STATUS,
START_NETWORK_CHANGE,
START_ERROR,
STOP,
START_NODE_STATUS_CHANGE,
START_RPC_TEST,
Expand Down Expand Up @@ -88,6 +89,7 @@ export const start = (network) => async (dispatch) => {
} catch (error) {
console.error('node start error', error);
dispatch({ type: STOP });
dispatch({ type: START_ERROR, payload: error.message });
} finally {
dispatch({ type: END_NODE_STATUS_CHANGE });
}
Expand Down
2 changes: 1 addition & 1 deletion app/ducks/nodeReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function nodeReducer(state = getInitialState(), action = {}) {
},
};
case START_ERROR:
return {...state, error: action.payload.error};
return {...state, error: action.payload};
case SET_NODE_INFO:
return {
...state,
Expand Down
6 changes: 5 additions & 1 deletion app/pages/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,15 @@ const OPEN_ROUTES = [
]

const ProtectedRoute = (props) => {
if (OPEN_ROUTES.includes(props.location.pathname)) {
return <Route {...props} />;
}

if (!props.wallets.length) {
return <Redirect to="/funding-options" />;
}

if (props.isLocked && !OPEN_ROUTES.includes(props.location.pathname)) {
if (props.isLocked) {
return <Redirect to="/login" />;
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@
"semver": "^7.3.5",
"shakedex": "https://github.com/chikeichan/shakedex#patch-3",
"source-map-support": "0.5.21",
"tcp-port-used": "1.0.1",
"uuid": "3.3.3",
"winston": "3.1.0"
}
Expand Down

0 comments on commit 34d6ea7

Please sign in to comment.