codeant-ai-for-open-source[bot] commented on code in PR #43696:
URL: https://github.com/apache/superset/pull/43696#discussion_r3890464992
##########
superset-frontend/src/middleware/realtime.ts:
##########
@@ -131,6 +171,28 @@ const openSocket = (thisGeneration: number): void => {
return;
}
socket = ws;
+
+ // Proactively refresh the channel cookie and reconnect before this
+ // connection's token expires, so an idle realtime surface (one making no
other
+ // HTTP requests, e.g. a quiet list view) does not silently lose the socket
at
+ // JWT expiry. The GET re-mints the httponly cookie via the Flask
after_request
+ // hook (inside its sliding window); the reconnect then rides the fresh
token.
+ // Best-effort: reconnect regardless of the GET's outcome (a stale cookie
just
+ // fails the handshake, and onclose retries).
+ if (enabled && tokenLifetimeMs > 0) {
+ keepaliveTimeoutId = window.setTimeout(() => {
+ if (thisGeneration !== generation || !hasActiveSocket()) return;
+ SupersetClient.get({ endpoint: COOKIE_REFRESH_ENDPOINT })
+ .catch(() => {})
+ .finally(() => {
+ if (thisGeneration !== generation) return;
+ generation += 1;
+ teardownSocket();
+ openSocket(generation);
Review Comment:
**Suggestion:** The refresh request can finish after the socket has closed
and a replacement is connected, then tear down that newer healthy socket and
start another connection. [race condition]
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c40ef9f6b76742af9fdab379b1689092&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=c40ef9f6b76742af9fdab379b1689092&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/middleware/realtime.ts
**Line:** 185:191
**Comment:**
*Race Condition: The refresh request can finish after the socket has
closed and a replacement is connected, then tear down that newer healthy socket
and start another connection.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43696&comment_hash=89a67176162426602e6c0d03b0da988db43432ef2151cbea1a2c6165b374471d&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43696&comment_hash=89a67176162426602e6c0d03b0da988db43432ef2151cbea1a2c6165b374471d&reaction=dislike'>๐</a>
--
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]