Skip to content

Commit ca94026

Browse files
authored
fix(sqllab): async queries no longer stuck at Running forever (#42896)
1 parent a3bc2d9 commit ca94026

2 files changed

Lines changed: 50 additions & 6 deletions

File tree

‎superset-frontend/src/SqlLab/reducers/sqlLab.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,49 @@ describe('sqlLabReducer', () => {
695695
);
696696
expect(newState.queries['sync-query'].state).toBe(QueryState.Fetching);
697697
});
698+
test('should move an async query from running to success when polling reports it finished', () => {
699+
const asyncQuery = {
700+
...query,
701+
id: 'async-query',
702+
state: QueryState.Running,
703+
runAsync: true,
704+
};
705+
newState = sqlLabReducer(
706+
{
707+
...newState,
708+
queries: { 'async-query': asyncQuery },
709+
},
710+
actions.refreshQueries({
711+
'async-query': {
712+
...asyncQuery,
713+
state: QueryState.Success,
714+
},
715+
}),
716+
);
717+
expect(newState.queries['async-query'].state).toBe(QueryState.Success);
718+
});
719+
test('should downgrade a premature poller success to fetching for a running sync query', () => {
720+
const syncQuery = {
721+
...query,
722+
id: 'sync-running',
723+
state: QueryState.Running,
724+
runAsync: false,
725+
results: null,
726+
};
727+
newState = sqlLabReducer(
728+
{
729+
...newState,
730+
queries: { 'sync-running': syncQuery },
731+
},
732+
actions.refreshQueries({
733+
'sync-running': {
734+
...syncQuery,
735+
state: QueryState.Success,
736+
},
737+
}),
738+
);
739+
expect(newState.queries['sync-running'].state).toBe(QueryState.Fetching);
740+
});
698741
});
699742
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
700743
describe('CLEAR_INACTIVE_QUERIES', () => {

‎superset-frontend/src/SqlLab/reducers/sqlLab.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,14 +769,15 @@ export default function sqlLabReducer(
769769
}),
770770
// race condition:
771771
// because of async behavior, sql lab may still poll a couple of seconds
772-
// when it started fetching or finished rendering results
772+
// after it started fetching or finished rendering results. Guard only
773+
// against re-applying a redundant Success onto a state that's already at
774+
// or past Success (Fetching/Success) — Running is strictly before
775+
// Success, so an incoming Success there is new information, not a stale
776+
// poll, and must be allowed through (otherwise an async query can never
777+
// leave Running once observed there).
773778
state:
774779
currentState === QueryState.Success &&
775-
[
776-
QueryState.Fetching,
777-
QueryState.Success,
778-
QueryState.Running,
779-
].includes(prevState)
780+
[QueryState.Fetching, QueryState.Success].includes(prevState)
780781
? prevState
781782
: currentState,
782783
};

0 commit comments

Comments
 (0)