Skip to content

Commit fa13182

Browse files
committed
[LW-10649] Stop cardano-node when restarting during auto-update
1 parent fbca8aa commit fa13182

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

nix/internal/linux-self-extracting-archive.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ if [ "$our_checksum" != 00000000000000000000000000000000000000000000000000000000
2424
exit 1
2525
fi
2626

27-
echo STATUS "Cleaning up the older version..."
27+
echo STATUS "Cleaning up already installed version(s)..."
2828
echo PROG 2/$num_steps
2929
target="$HOME"/.daedalus/@CLUSTER@
3030
if [ -e "$target" ] ; then
31-
echo "Found an older version of Daedalus "@CLUSTER@", removing it..."
31+
echo "Found another version of Daedalus "@CLUSTER@", removing it..."
3232
chmod -R +w "$target"
3333
rm -rf "$target"
3434
fi

source/main/cardano/setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export const setupCardanoNode = (
170170
logger.info(
171171
'CardanoNode applied an update. Exiting Daedalus with code 20.'
172172
);
173+
// FIXME: Dead code? This channel doesn’t seem used. The node doesn’t apply its own updates…?
173174
safeExitWithCode(20);
174175
});
175176
return Promise.resolve();

source/main/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,17 @@ EventEmitter.defaultMaxListeners = 100; // Default: 10
8585
const safeExit = async () => {
8686
pauseActiveDownloads();
8787

88+
const exitCode =
89+
(mainWindow as any).daedalusExitCode !== undefined
90+
? (mainWindow as any).daedalusExitCode
91+
: 0;
92+
8893
if (!cardanoNode || cardanoNode.state === CardanoNodeStates.STOPPED) {
8994
// @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
90-
logger.info('Daedalus:safeExit: exiting Daedalus with code 0', {
91-
code: 0,
95+
logger.info(`Daedalus:safeExit: exiting Daedalus with code ${exitCode}`, {
96+
code: exitCode,
9297
});
93-
return safeExitWithCode(0);
98+
return safeExitWithCode(exitCode);
9499
}
95100

96101
if (cardanoNode.state === CardanoNodeStates.STOPPING) {
@@ -108,16 +113,16 @@ const safeExit = async () => {
108113
});
109114
await cardanoNode.stop();
110115
// @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
111-
logger.info('Daedalus:safeExit: exiting Daedalus with code 0', {
112-
code: 0,
116+
logger.info(`Daedalus:safeExit: exiting Daedalus with code ${code}`, {
117+
code: exitCode,
113118
});
114-
safeExitWithCode(0);
119+
safeExitWithCode(exitCode);
115120
} catch (error) {
116121
// @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
117122
logger.error('Daedalus:safeExit: cardano-node did not exit correctly', {
118123
error,
119124
});
120-
safeExitWithCode(0);
125+
safeExitWithCode(exitCode);
121126
}
122127
};
123128

source/main/ipc/manageAppUpdateChannel.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
} from '../../common/ipc/api';
1212
import { UPDATE_INSTALLATION_STATUSES as statuses } from '../../common/config/appUpdateConfig';
1313
import { environment } from '../environment';
14-
import { safeExitWithCode } from '../utils/safeExitWithCode';
1514
import { logger } from '../utils/logging';
1615
import { launcherConfig } from '../config';
1716
// IpcChannel<Incoming, Outgoing>
@@ -169,7 +168,11 @@ export const handleManageAppUpdateRequests = (window: BrowserWindow) => {
169168
return reject();
170169
}
171170

172-
safeExitWithCode(20);
171+
// We need to also wait for `cardano-node` to exit cleanly, otherwise the new auto-updated version
172+
// is showing the new node crashing, because the old one is still running for around 30 seconds:
173+
// WRONG: safeExitWithCode(20);
174+
(window as any).daedalusExitCode = 20;
175+
window.close();
173176
return resolve(response(true, functionPrefix));
174177
});
175178
});

source/main/utils/buildAppMenus.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { environment } from '../environment';
44
import { winLinuxMenu } from '../menus/win-linux';
55
import { osxMenu } from '../menus/osx';
66
import { logger } from './logging';
7-
import { safeExitWithCode } from './safeExitWithCode';
87
import { CardanoNode } from '../cardano/CardanoNode';
98
import { DIALOGS, PAGES } from '../../common/ipc/constants';
109
import { showUiPartChannel } from '../ipc/control-ui-parts';
@@ -64,7 +63,10 @@ export const buildAppMenus = async (
6463
logger.info('Exiting Daedalus with code 21', {
6564
code: 21,
6665
});
67-
safeExitWithCode(21);
66+
// We have to make sure that cardano-node exits, otherwise we get DB locked errors at startup:
67+
// WRONG: safeExitWithCode(21);
68+
(mainWindow as any).daedalusExitCode = 21;
69+
mainWindow.close();
6870
};
6971

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

8186
const toggleBlankScreenFix = async (item) => {

0 commit comments

Comments
 (0)