mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-28 09:17:18 +00:00
Cleanup after child-process is terminated
Change-type: patch Signed-off-by: Lorenzo Alberto Maria Ambrosi <lorenzothunder.ambrosi@gmail.com>
This commit is contained in:
parent
74a78076cf
commit
3c77800b1d
@ -334,11 +334,18 @@ function storeReducer(
|
|||||||
action.data.results.averageFlashingSpeed = state.get(
|
action.data.results.averageFlashingSpeed = state.get(
|
||||||
'lastAverageFlashingSpeed',
|
'lastAverageFlashingSpeed',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (action.data.results.skip) {
|
||||||
|
return state
|
||||||
|
.set('isFlashing', false)
|
||||||
|
.set('flashResults', Immutable.fromJS(action.data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return state
|
return state
|
||||||
.set('isFlashing', false)
|
.set('isFlashing', false)
|
||||||
.set('flashResults', Immutable.fromJS(action.data));
|
.set('flashResults', Immutable.fromJS(action.data))
|
||||||
|
.set('flashState', DEFAULT_STATE.get('flashState'));
|
||||||
}
|
}
|
||||||
|
|
||||||
case Actions.SELECT_TARGET: {
|
case Actions.SELECT_TARGET: {
|
||||||
|
@ -55,8 +55,9 @@ function log(message: string) {
|
|||||||
/**
|
/**
|
||||||
* @summary Terminate the child writer process
|
* @summary Terminate the child writer process
|
||||||
*/
|
*/
|
||||||
function terminate(exitCode: number) {
|
async function terminate(exitCode: number) {
|
||||||
ipc.disconnect(IPC_SERVER_ID);
|
ipc.disconnect(IPC_SERVER_ID);
|
||||||
|
await cleanupTmpFiles(Date.now());
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
process.exit(exitCode || SUCCESS);
|
process.exit(exitCode || SUCCESS);
|
||||||
});
|
});
|
||||||
@ -68,7 +69,7 @@ function terminate(exitCode: number) {
|
|||||||
async function handleError(error: Error) {
|
async function handleError(error: Error) {
|
||||||
ipc.of[IPC_SERVER_ID].emit('error', toJSON(error));
|
ipc.of[IPC_SERVER_ID].emit('error', toJSON(error));
|
||||||
await delay(DISCONNECT_DELAY);
|
await delay(DISCONNECT_DELAY);
|
||||||
terminate(GENERAL_ERROR);
|
await terminate(GENERAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface WriteResult {
|
interface WriteResult {
|
||||||
@ -165,22 +166,22 @@ ipc.connectTo(IPC_SERVER_ID, () => {
|
|||||||
// no flashing information is available, then it will
|
// no flashing information is available, then it will
|
||||||
// assume that the child died halfway through.
|
// assume that the child died halfway through.
|
||||||
|
|
||||||
process.once('SIGINT', () => {
|
process.once('SIGINT', async () => {
|
||||||
terminate(SUCCESS);
|
await terminate(SUCCESS);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.once('SIGTERM', () => {
|
process.once('SIGTERM', async () => {
|
||||||
terminate(SUCCESS);
|
await terminate(SUCCESS);
|
||||||
});
|
});
|
||||||
|
|
||||||
// The IPC server failed. Abort.
|
// The IPC server failed. Abort.
|
||||||
ipc.of[IPC_SERVER_ID].on('error', () => {
|
ipc.of[IPC_SERVER_ID].on('error', async () => {
|
||||||
terminate(SUCCESS);
|
await terminate(SUCCESS);
|
||||||
});
|
});
|
||||||
|
|
||||||
// The IPC server was disconnected. Abort.
|
// The IPC server was disconnected. Abort.
|
||||||
ipc.of[IPC_SERVER_ID].on('disconnect', () => {
|
ipc.of[IPC_SERVER_ID].on('disconnect', async () => {
|
||||||
terminate(SUCCESS);
|
await terminate(SUCCESS);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc.of[IPC_SERVER_ID].on('write', async (options: WriteOptions) => {
|
ipc.of[IPC_SERVER_ID].on('write', async (options: WriteOptions) => {
|
||||||
@ -205,14 +206,14 @@ ipc.connectTo(IPC_SERVER_ID, () => {
|
|||||||
log('Abort');
|
log('Abort');
|
||||||
ipc.of[IPC_SERVER_ID].emit('abort');
|
ipc.of[IPC_SERVER_ID].emit('abort');
|
||||||
await delay(DISCONNECT_DELAY);
|
await delay(DISCONNECT_DELAY);
|
||||||
terminate(exitCode);
|
await terminate(exitCode);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSkip = async () => {
|
const onSkip = async () => {
|
||||||
log('Skip validation');
|
log('Skip validation');
|
||||||
ipc.of[IPC_SERVER_ID].emit('skip');
|
ipc.of[IPC_SERVER_ID].emit('skip');
|
||||||
await delay(DISCONNECT_DELAY);
|
await delay(DISCONNECT_DELAY);
|
||||||
terminate(exitCode);
|
await terminate(exitCode);
|
||||||
};
|
};
|
||||||
|
|
||||||
ipc.of[IPC_SERVER_ID].on('cancel', onAbort);
|
ipc.of[IPC_SERVER_ID].on('cancel', onAbort);
|
||||||
@ -286,7 +287,7 @@ ipc.connectTo(IPC_SERVER_ID, () => {
|
|||||||
});
|
});
|
||||||
ipc.of[IPC_SERVER_ID].emit('done', { results });
|
ipc.of[IPC_SERVER_ID].emit('done', { results });
|
||||||
await delay(DISCONNECT_DELAY);
|
await delay(DISCONNECT_DELAY);
|
||||||
terminate(exitCode);
|
await terminate(exitCode);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(`Error: ${error.message}`);
|
log(`Error: ${error.message}`);
|
||||||
exitCode = GENERAL_ERROR;
|
exitCode = GENERAL_ERROR;
|
||||||
|
@ -393,6 +393,7 @@ describe('Model: flashState', function () {
|
|||||||
|
|
||||||
expect(flashResults).to.deep.equal({
|
expect(flashResults).to.deep.equal({
|
||||||
cancelled: false,
|
cancelled: false,
|
||||||
|
skip: false,
|
||||||
sourceChecksum: '1234',
|
sourceChecksum: '1234',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user