Wang1rrr opened a new pull request, #4986:
URL: https://github.com/apache/rocketmq-dashboard/pull/4986
## What is the purpose of the change
Fixes two uncancelled `setTimeout` calls: the metrics explorer fallback and
the cluster page's
instance-load retry. Both could mutate state and fire requests after the
component unmounted, and
both could stack up duplicate work while their dependencies changed.
## Root cause
**`MetricsExplorer.tsx`** schedules the "selected data source dropped out of
scope" fallback
without keeping the timer:
```ts
window.setTimeout(() => {
dataSourceCredentialsRef.current = null;
dataSourceKeyRef.current = '';
setDataSourceKey('');
setPendingDataSource(null);
void loadAll(selectedProfile, selectedRange);
if (appliedCustomPromql) void runCustomQuery(appliedCustomPromql,
selectedRange);
}, 0);
```
The effect depends on `loadAll`, `runCustomQuery`, `selectedProfile`,
`selectedRange`,
`appliedCustomPromql` and `availableDataSources`, so it re-runs often. Every
run schedules a new
timer that is never cancelled: after unmount the callback still calls
`setState` and issues two
queries, and while the dependencies keep changing several fallbacks fire in
a row and overwrite
each other's results.
**`cluster/index.tsx`** schedules the instance-list retry the same way:
```ts
window.setTimeout(() => setInstanceLoadKey((key) => key + 1), 3000);
```
If the user navigates away within the 3 s window (or the effect re-runs),
the retry still bumps
`instanceLoadKey` and triggers another load for a page that is no longer
mounted.
## What is fixed
Both effects now keep the timer handle and clear it in the effect cleanup,
so a pending fallback
or retry never outlives its run.
## Verification
`npm test` passes: 139 files / 1285 tests on the `rocketmq-studio` trunk,
plus `vite build`
(`tsc -b` + `vite build`) and `eslint src --quiet` with no errors. The
cluster retry keeps its
existing behaviour (max 3 retries, then surface the error) — only the
cancellation is added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]