rusackas commented on code in PR #40870:
URL: https://github.com/apache/superset/pull/40870#discussion_r3376104989
##########
superset-embedded-sdk/src/index.ts:
##########
@@ -248,20 +267,33 @@ export async function embedDashboard({
}
const [guestToken, ourPort]: [string, Switchboard] = await Promise.all([
- fetchGuestToken(),
+ fetchGuestTokenWithTimeout(),
mountIframe(),
]);
ourPort.emit('guestToken', { guestToken });
log('sent guest token');
+ // Track the pending refresh timer so it can be cancelled on unmount, and
+ // stop the cycle once unmounted so it cannot leak across mount/unmount
cycles.
+ let refreshTimer: ReturnType<typeof setTimeout> | undefined;
+ let unmounted = false;
+
async function refreshGuestToken() {
- const newGuestToken = await fetchGuestToken();
+ if (unmounted) return;
+ const newGuestToken = await fetchGuestTokenWithTimeout();
+ if (unmounted) return;
ourPort.emit('guestToken', { guestToken: newGuestToken });
- setTimeout(refreshGuestToken, getGuestTokenRefreshTiming(newGuestToken));
+ refreshTimer = setTimeout(
+ refreshGuestToken,
+ getGuestTokenRefreshTiming(newGuestToken),
+ );
}
Review Comment:
Good catch. Fixed in 60f8df384a: `refreshGuestToken` now wraps the fetch in
try/catch and reschedules a retry (`DEFAULT_TOKEN_REFRESH_RETRY_MS`) on
failure/timeout, so a single transient error no longer kills the refresh loop
for the rest of the session.
##########
superset-embedded-sdk/src/index.ts:
##########
@@ -248,20 +267,33 @@ export async function embedDashboard({
}
const [guestToken, ourPort]: [string, Switchboard] = await Promise.all([
- fetchGuestToken(),
+ fetchGuestTokenWithTimeout(),
mountIframe(),
]);
Review Comment:
Good catch. Fixed in 60f8df384a: the initial `Promise.all` is now wrapped in
try/catch and tears down the mount point (`mountPoint.replaceChildren()`)
before rethrowing, so a failed/timed-out initial token fetch no longer leaves
an orphaned iframe mounted.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]