Copilot commented on code in PR #37280:
URL: https://github.com/apache/superset/pull/37280#discussion_r2713921073


##########
superset-embedded-sdk/src/index.ts:
##########
@@ -249,13 +249,14 @@ export async function embedDashboard({
   ourPort.emit('guestToken', { guestToken });
   log('sent guest token');
 
+  let refreshTokenTimerId: ReturnType<typeof setTimeout> | null = null;
   async function refreshGuestToken() {
     const newGuestToken = await fetchGuestToken();
     ourPort.emit('guestToken', { guestToken: newGuestToken });
-    setTimeout(refreshGuestToken, getGuestTokenRefreshTiming(newGuestToken));
+    refreshTokenTimerId = setTimeout(refreshGuestToken, 
getGuestTokenRefreshTiming(newGuestToken));
   }

Review Comment:
   There's a race condition in the timer cleanup logic. If unmount() is called 
while refreshGuestToken() is executing (after the timer has fired but before 
the new timer is set at line 256), the new timer won't be cleared. 
   
   To fix this, consider adding a flag to prevent setting new timers after 
unmount is called, or setting refreshTokenTimerId to null immediately when the 
timer fires, or clearing it at the start of refreshGuestToken before the async 
operation.



##########
superset-embedded-sdk/src/index.ts:
##########
@@ -277,7 +278,11 @@ export async function embedDashboard({
 
   function unmount() {
     log('unmounting');
-    //@ts-ignore
+
+    if (refreshTokenTimerId) {
+      clearTimeout(refreshTokenTimerId);
+    }

Review Comment:
   The new timer cleanup functionality in the unmount method lacks test 
coverage. Consider adding tests to verify that clearTimeout is called when 
unmount is invoked, and that no timers continue running after unmount.



-- 
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]

Reply via email to