mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[ML] @kbn/ml-response-stream
: Fix race condition related to throttling. (#162803)
Fixes a race condition in the case where a response stream finishes and sets `isRunning` to `false`, but `useThrottle` didn't trigger it's last update yet within the refresh rate. In the case of log rate analysis, `isRunning` could be set to `false` too early and the UI wouldn't consider later throttled updates (for example, setting `loaded=1` which would result in inconsistent UI state). The fix in this case is to return the unthrottled raw data instead of the throttled one as soon as the stream finished.
This commit is contained in:
parent
f0050dbc70
commit
96de1482e0
1 changed files with 4 additions and 1 deletions
|
@ -129,7 +129,10 @@ export function useFetchStream<B extends object, R extends Reducer<any, any>>(
|
|||
|
||||
return {
|
||||
cancel,
|
||||
data: dataThrottled,
|
||||
// To avoid a race condition where the stream already ended but `useThrottle` would
|
||||
// yet have to trigger another update within the throttling interval, we'll return
|
||||
// the unthrottled data once the stream is complete.
|
||||
data: isRunning ? dataThrottled : data,
|
||||
dispatch,
|
||||
errors,
|
||||
isCancelled,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue