Skip to content

Commit

Permalink
[LW-10649] Stop cardano-node when restarting during auto-update
Browse files Browse the repository at this point in the history
  • Loading branch information
michalrus committed Jul 10, 2024
1 parent fbca8aa commit fa13182
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions nix/internal/linux-self-extracting-archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ if [ "$our_checksum" != 00000000000000000000000000000000000000000000000000000000
exit 1
fi

echo STATUS "Cleaning up the older version..."
echo STATUS "Cleaning up already installed version(s)..."
echo PROG 2/$num_steps
target="$HOME"/.daedalus/@CLUSTER@
if [ -e "$target" ] ; then
echo "Found an older version of Daedalus "@CLUSTER@", removing it..."
echo "Found another version of Daedalus "@CLUSTER@", removing it..."
chmod -R +w "$target"
rm -rf "$target"
fi
Expand Down
1 change: 1 addition & 0 deletions source/main/cardano/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export const setupCardanoNode = (
logger.info(
'CardanoNode applied an update. Exiting Daedalus with code 20.'
);
// FIXME: Dead code? This channel doesn’t seem used. The node doesn’t apply its own updates…?
safeExitWithCode(20);
});
return Promise.resolve();
Expand Down
19 changes: 12 additions & 7 deletions source/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,17 @@ EventEmitter.defaultMaxListeners = 100; // Default: 10
const safeExit = async () => {
pauseActiveDownloads();

const exitCode =
(mainWindow as any).daedalusExitCode !== undefined
? (mainWindow as any).daedalusExitCode
: 0;

if (!cardanoNode || cardanoNode.state === CardanoNodeStates.STOPPED) {
// @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
logger.info('Daedalus:safeExit: exiting Daedalus with code 0', {
code: 0,
logger.info(`Daedalus:safeExit: exiting Daedalus with code ${exitCode}`, {
code: exitCode,
});
return safeExitWithCode(0);
return safeExitWithCode(exitCode);
}

if (cardanoNode.state === CardanoNodeStates.STOPPING) {
Expand All @@ -108,16 +113,16 @@ const safeExit = async () => {
});
await cardanoNode.stop();
// @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
logger.info('Daedalus:safeExit: exiting Daedalus with code 0', {
code: 0,
logger.info(`Daedalus:safeExit: exiting Daedalus with code ${code}`, {
code: exitCode,
});
safeExitWithCode(0);
safeExitWithCode(exitCode);
} catch (error) {
// @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
logger.error('Daedalus:safeExit: cardano-node did not exit correctly', {
error,
});
safeExitWithCode(0);
safeExitWithCode(exitCode);
}
};

Expand Down
7 changes: 5 additions & 2 deletions source/main/ipc/manageAppUpdateChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
} from '../../common/ipc/api';
import { UPDATE_INSTALLATION_STATUSES as statuses } from '../../common/config/appUpdateConfig';
import { environment } from '../environment';
import { safeExitWithCode } from '../utils/safeExitWithCode';
import { logger } from '../utils/logging';
import { launcherConfig } from '../config';
// IpcChannel<Incoming, Outgoing>
Expand Down Expand Up @@ -169,7 +168,11 @@ export const handleManageAppUpdateRequests = (window: BrowserWindow) => {
return reject();
}

safeExitWithCode(20);
// We need to also wait for `cardano-node` to exit cleanly, otherwise the new auto-updated version
// is showing the new node crashing, because the old one is still running for around 30 seconds:
// WRONG: safeExitWithCode(20);
(window as any).daedalusExitCode = 20;
window.close();
return resolve(response(true, functionPrefix));
});
});
Expand Down
11 changes: 8 additions & 3 deletions source/main/utils/buildAppMenus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { environment } from '../environment';
import { winLinuxMenu } from '../menus/win-linux';
import { osxMenu } from '../menus/osx';
import { logger } from './logging';
import { safeExitWithCode } from './safeExitWithCode';
import { CardanoNode } from '../cardano/CardanoNode';
import { DIALOGS, PAGES } from '../../common/ipc/constants';
import { showUiPartChannel } from '../ipc/control-ui-parts';
Expand Down Expand Up @@ -64,7 +63,10 @@ export const buildAppMenus = async (
logger.info('Exiting Daedalus with code 21', {
code: 21,
});
safeExitWithCode(21);
// We have to make sure that cardano-node exits, otherwise we get DB locked errors at startup:
// WRONG: safeExitWithCode(21);
(mainWindow as any).daedalusExitCode = 21;
mainWindow.close();
};

const restartWithoutBlankScreenFix = async () => {
Expand All @@ -75,7 +77,10 @@ export const buildAppMenus = async (
logger.info('Exiting Daedalus with code 22', {
code: 22,
});
safeExitWithCode(22);
// We have to make sure that cardano-node exits, otherwise we get DB locked errors at startup:
// WRONG: safeExitWithCode(22);
(mainWindow as any).daedalusExitCode = 22;
mainWindow.close();
};

const toggleBlankScreenFix = async (item) => {
Expand Down

0 comments on commit fa13182

Please sign in to comment.