Skip to content

Commit a4792fd

Browse files
authored
fix: cancel previous multipart request if the new one starts (#2559)
1 parent 77e9bf4 commit a4792fd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ export default function QueryEditor(props: QueryEditorProps) {
144144
}
145145
const queryId = uuidv4();
146146

147+
// Abort previous query if there was any
148+
queryManagerInstance.abortQuery();
149+
147150
if (isStreamingEnabled) {
148151
const query = streamQuery({
149152
actionType: 'execute',

src/store/reducers/query/query.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ export const queryApi = api.injectEndpoints({
296296
return {data: null};
297297
} catch (error) {
298298
const state = getState() as RootState;
299+
if (state.query.result?.startTime !== startTime) {
300+
// This query is no longer current, don't update state
301+
return {error};
302+
}
299303
dispatch(
300304
setQueryResult({
301305
...state.query.result,
@@ -321,7 +325,7 @@ export const queryApi = api.injectEndpoints({
321325
enableTracingLevel,
322326
queryId,
323327
},
324-
{signal, dispatch},
328+
{signal, dispatch, getState},
325329
) => {
326330
const startTime = Date.now();
327331
dispatch(
@@ -410,6 +414,11 @@ export const queryApi = api.injectEndpoints({
410414
);
411415
return {data: null};
412416
} catch (error) {
417+
const state = getState() as RootState;
418+
if (state.query.result?.startTime !== startTime) {
419+
// This query is no longer current, don't update state
420+
return {error};
421+
}
413422
dispatch(
414423
setQueryResult({
415424
type: actionType,

0 commit comments

Comments
 (0)