diff --git a/CHANGELOG.md b/CHANGELOG.md index d4620f426..e034cdfc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ 1. [#4408](https://github.com/influxdata/chronograf/pull/4408): Render null data point values in Alerts Table as mdashes 1. [#4466](https://github.com/influxdata/chronograf/pull/4466): Maintain focus on Flux Editor text area when adding nodes via code 1. [#4479](https://github.com/influxdata/chronograf/pull/4479): Add validation to Alert Rule messages +1. [#4599](https://github.com/influxdata/chronograf/pull/4599): Fix search results updating race condition ## v1.6.2 [2018-09-06] diff --git a/ui/src/logs/containers/LogsPage.tsx b/ui/src/logs/containers/LogsPage.tsx index fc7349044..ec52af23c 100644 --- a/ui/src/logs/containers/LogsPage.tsx +++ b/ui/src/logs/containers/LogsPage.tsx @@ -350,7 +350,7 @@ class LogsPage extends Component { if (this.props.nextNewerLowerBound > maxNewerFetchForward) { this.props.setNextNewerLowerBound(Date.now()) - this.currentNewerChunksGenerator.cancel() + await this.currentNewerChunksGenerator.cancelAsync() } await this.props.fetchNewerChunkAsync() @@ -422,9 +422,6 @@ class LogsPage extends Component { console.error(error) } - if (!this.currentNewerChunksGenerator.isCanceled) { - this.currentNewerChunksGenerator.cancel() - } this.loadingNewer = false this.currentNewerChunksGenerator = null } @@ -446,10 +443,6 @@ class LogsPage extends Component { console.error(error) } - if (!this.currentOlderChunksGenerator.isCanceled) { - this.currentOlderChunksGenerator.cancel() - } - this.currentOlderChunksGenerator = null } @@ -460,16 +453,16 @@ class LogsPage extends Component { } } - private cancelChunks() { - if (this.currentNewerChunksGenerator) { - this.currentNewerChunksGenerator.cancel() - this.currentNewerChunksGenerator = null - } + private cancelChunks = async () => { + const cancelPendingChunks = _.compact([ + this.currentNewerChunksGenerator, + this.currentOlderChunksGenerator, + ]).map(req => req.cancelAsync()) - if (this.currentOlderChunksGenerator) { - this.currentOlderChunksGenerator.cancel() - this.currentOlderChunksGenerator = null - } + await Promise.all(cancelPendingChunks) + + this.currentNewerChunksGenerator = null + this.currentOlderChunksGenerator = null } private get tableScrollToRow() { @@ -858,9 +851,9 @@ class LogsPage extends Component { this.updateTableData(SearchStatus.UpdatingNamespace) } - private updateTableData(searchStatus: SearchStatus) { + private updateTableData = async (searchStatus: SearchStatus) => { this.clearTailInterval() - this.cancelChunks() + await this.cancelChunks() this.props.clearSearchData(searchStatus) } diff --git a/ui/src/logs/utils/fetchUntil.ts b/ui/src/logs/utils/fetchUntil.ts index 15d7065fb..c94061fe5 100644 --- a/ui/src/logs/utils/fetchUntil.ts +++ b/ui/src/logs/utils/fetchUntil.ts @@ -11,12 +11,13 @@ export function fetchUntil( const requests = fetchUnless(() => isCanceled || predicate(), request) const promise = fetchEachAsync(requests) - + const cancelAsync = async () => { + isCanceled = true + await promise + } return { promise, - cancel() { - isCanceled = true - }, + cancelAsync, isCanceled, } } diff --git a/ui/src/types/logs.ts b/ui/src/types/logs.ts index eccc5000d..0db20b180 100644 --- a/ui/src/types/logs.ts +++ b/ui/src/types/logs.ts @@ -203,6 +203,6 @@ export interface MatchSection { export interface FetchLoop { promise: Promise - cancel: () => void + cancelAsync: () => Promise isCanceled: boolean }