mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): race condition with progress
There's a race condition where a canceled session may emit a progress event or two after it's been canceled, and the progress image isn't cleared out. To resolve this, the system slice tracks canceled session ids. When a progress event comes in, we check the cancellations and skip setting the progress if canceled.
This commit is contained in:
parent
fb93e686b2
commit
0758e9cb9b
@ -31,6 +31,7 @@ const initialSystemState: SystemState = {
|
|||||||
shouldUseWatermarker: false,
|
shouldUseWatermarker: false,
|
||||||
shouldEnableInformationalPopovers: false,
|
shouldEnableInformationalPopovers: false,
|
||||||
status: 'DISCONNECTED',
|
status: 'DISCONNECTED',
|
||||||
|
cancellations: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const systemSlice = createSlice({
|
export const systemSlice = createSlice({
|
||||||
@ -88,6 +89,7 @@ export const systemSlice = createSlice({
|
|||||||
* Invocation Started
|
* Invocation Started
|
||||||
*/
|
*/
|
||||||
builder.addCase(socketInvocationStarted, (state) => {
|
builder.addCase(socketInvocationStarted, (state) => {
|
||||||
|
state.cancellations = [];
|
||||||
state.denoiseProgress = null;
|
state.denoiseProgress = null;
|
||||||
state.status = 'PROCESSING';
|
state.status = 'PROCESSING';
|
||||||
});
|
});
|
||||||
@ -105,6 +107,12 @@ export const systemSlice = createSlice({
|
|||||||
queue_batch_id: batch_id,
|
queue_batch_id: batch_id,
|
||||||
} = action.payload.data;
|
} = action.payload.data;
|
||||||
|
|
||||||
|
if (state.cancellations.includes(session_id)) {
|
||||||
|
// Do not update the progress if this session has been cancelled. This prevents a race condition where we get a
|
||||||
|
// progress update after the session has been cancelled.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
state.denoiseProgress = {
|
state.denoiseProgress = {
|
||||||
step,
|
step,
|
||||||
total_steps,
|
total_steps,
|
||||||
@ -146,6 +154,7 @@ export const systemSlice = createSlice({
|
|||||||
if (['completed', 'canceled', 'failed'].includes(action.payload.data.queue_item.status)) {
|
if (['completed', 'canceled', 'failed'].includes(action.payload.data.queue_item.status)) {
|
||||||
state.status = 'CONNECTED';
|
state.status = 'CONNECTED';
|
||||||
state.denoiseProgress = null;
|
state.denoiseProgress = null;
|
||||||
|
state.cancellations.push(action.payload.data.queue_item.session_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -177,5 +186,5 @@ export const systemPersistConfig: PersistConfig<SystemState> = {
|
|||||||
name: systemSlice.name,
|
name: systemSlice.name,
|
||||||
initialState: initialSystemState,
|
initialState: initialSystemState,
|
||||||
migrate: migrateSystemState,
|
migrate: migrateSystemState,
|
||||||
persistDenylist: ['isConnected', 'denoiseProgress', 'status'],
|
persistDenylist: ['isConnected', 'denoiseProgress', 'status', 'cancellations'],
|
||||||
};
|
};
|
||||||
|
@ -55,4 +55,5 @@ export interface SystemState {
|
|||||||
shouldUseWatermarker: boolean;
|
shouldUseWatermarker: boolean;
|
||||||
status: SystemStatus;
|
status: SystemStatus;
|
||||||
shouldEnableInformationalPopovers: boolean;
|
shouldEnableInformationalPopovers: boolean;
|
||||||
|
cancellations: string[]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user