-
-
Notifications
You must be signed in to change notification settings - Fork 158
fix: bugfix for logout, oncecell for sse #1503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: bugfix for logout, oncecell for sse #1503
Conversation
WalkthroughThis change replaces Lazy statics with OnceCell for the SSE handler and removes the Option wrapper from the OIDC client OnceCell, updating call sites to use guarded retrievals and simplified get() patterns; token-refresh awaits the read lock before refresh. (≈40 words) Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
Comment |
1db1442 to
6ff713a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/handlers/http/oidc.rs (1)
83-83: Consider simplifying the OIDC client retrieval.The
.map(|c| c.as_ref())is unnecessary here. SinceArcimplementsDeref, you can use the&Arc<RwLock<GlobalClient>>directly with.read().await. However, this doesn't affect correctness.🔎 Suggested simplification
- let oidc_client = OIDC_CLIENT.get().map(|c| c.as_ref()); + let oidc_client = OIDC_CLIENT.get();
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/alerts/mod.rssrc/handlers/http/middleware.rssrc/handlers/http/modal/mod.rssrc/handlers/http/oidc.rssrc/sse/mod.rs
🧰 Additional context used
🧬 Code graph analysis (1)
src/handlers/http/oidc.rs (2)
src/utils/actix.rs (2)
extract_session_key_from_req(51-71)req(31-31)src/handlers/http/modal/mod.rs (1)
client(75-77)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Build Default aarch64-apple-darwin
- GitHub Check: Build Default x86_64-unknown-linux-gnu
- GitHub Check: Build Default aarch64-unknown-linux-gnu
- GitHub Check: Build Default x86_64-pc-windows-msvc
- GitHub Check: Build Kafka x86_64-unknown-linux-gnu
- GitHub Check: Build Kafka aarch64-apple-darwin
- GitHub Check: coverage
- GitHub Check: Quest Smoke and Load Tests for Standalone deployments
- GitHub Check: Quest Smoke and Load Tests for Distributed deployments
🔇 Additional comments (9)
src/sse/mod.rs (2)
29-29: LGTM! OnceCell is a good choice for deferred initialization.The switch from
LazytoOnceCellensures theBroadcaster(and its ping loop) is only created when the first SSE client actually connects, improving resource efficiency for deployments that don't use SSE.Also applies to: 39-39
177-180: LGTM! Proper initialization pattern.Using
get_or_init(Broadcaster::create)ensures thread-safe, lazy initialization exactly when needed. Thenew_clientcall is correctly chained after initialization.src/alerts/mod.rs (1)
637-639: LGTM! Proper guard for OnceCell access.The
SSE_HANDLER.get()pattern correctly handles the case where no SSE clients have connected yet (and thus the handler isn't initialized). Silently skipping the broadcast when the handler is absent is appropriate since there are no clients to receive the message anyway.src/handlers/http/oidc.rs (2)
148-175: LGTM! This fixes the logout bug mentioned in the PR.The logout flow now correctly handles the case where OIDC is not configured. Previously, the code assumed
OIDC_CLIENTwas always present, which caused issues. Theif let Some(client)guard ensures graceful handling when OIDC is not set up.
179-184: LGTM! Proper error handling for missing OIDC client.Returning
Unauthorizedwhen the OIDC client is not configured is appropriate for thereply_logincallback endpoint, as this endpoint should only be reachable when OIDC is configured.src/handlers/http/modal/mod.rs (2)
63-63: LGTM! Good type simplification.Removing the
Optionwrapper from insideOnceCellis a cleaner design. Now the semantics are clear:OIDC_CLIENT.get()returnsNoneif OIDC is not configured, andSome(...)if it is. This eliminates the redundantOption<Option<...>>pattern.
116-121: LGTM! Proper conditional initialization.The OIDC client is only initialized when configuration is present. Using
get_or_initensures idempotent, thread-safe initialization even ifstartwere called multiple times.src/handlers/http/middleware.rs (2)
185-185: LGTM! Simplified OIDC client retrieval.The direct
OIDC_CLIENT.get()call is cleaner than the previous nestedOptionhandling, aligning with the type change inmodal/mod.rs.
203-220: LGTM! Correct async RwLock handling for token refresh.The
client.read().await.client().refresh_token(...)chain correctly acquires the read lock before accessing the client. Error handling properly removes the session and returnsUnauthorizedon refresh failure.
logout flow incorrectly assumed the oidc client to always be present shifted sse handler from lazy to oncecell
6ff713a to
8aedf5e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/alerts/mod.rssrc/handlers/http/middleware.rssrc/handlers/http/modal/mod.rssrc/handlers/http/oidc.rssrc/sse/mod.rs
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-24T11:09:21.781Z
Learnt from: nikhilsinhaparseable
Repo: parseablehq/parseable PR: 1388
File: src/alerts/mod.rs:88-104
Timestamp: 2025-07-24T11:09:21.781Z
Learning: In the Parseable alert system (src/alerts/mod.rs), alert versions are server-generated and controlled via CURRENT_ALERTS_VERSION constant, not user input. The AlertVerison enum's From<&str> implementation correctly defaults unknown versions to V2 since the server only generates known versions (v1, v2). Unknown versions would only occur in exceptional cases like file corruption, making the current fallback approach appropriate.
Applied to files:
src/alerts/mod.rs
🧬 Code graph analysis (1)
src/handlers/http/oidc.rs (2)
src/utils/actix.rs (2)
extract_session_key_from_req(51-71)req(31-31)src/handlers/http/modal/mod.rs (1)
client(75-77)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: Quest Smoke and Load Tests for Standalone deployments
- GitHub Check: Quest Smoke and Load Tests for Distributed deployments
- GitHub Check: coverage
- GitHub Check: Build Default x86_64-pc-windows-msvc
- GitHub Check: Build Default aarch64-unknown-linux-gnu
- GitHub Check: Build Default x86_64-unknown-linux-gnu
- GitHub Check: Build Kafka x86_64-unknown-linux-gnu
- GitHub Check: Build Kafka aarch64-apple-darwin
🔇 Additional comments (10)
src/alerts/mod.rs (1)
637-640: LGTM! SSE broadcast now safely handles uninitialized handler.The guard pattern correctly checks if the SSE handler exists before broadcasting. This aligns with the OnceCell change where the handler is only initialized when the first SSE client connects.
src/sse/mod.rs (3)
29-29: LGTM! Import updated for OnceCell.
39-39: LGTM! SSE handler initialization pattern changed to OnceCell.The shift from
LazytoOnceCellis appropriate as it provides explicit control over initialization timing and allows checking whether the handler has been initialized.
177-180: LGTM! Handler initialization on first client connection.The
get_or_initensures the broadcaster is created when the first SSE client registers, which is more efficient than eager initialization.src/handlers/http/modal/mod.rs (2)
63-63: LGTM! OIDC client type simplified.Removing the
Optionwrapper from the OnceCell's inner type is cleaner. The OnceCell itself handles presence/absence via.get()returningOption<&T>.
120-120: LGTM! Initialization closure simplified.The closure now directly returns
Arc<RwLock<GlobalClient>>instead of wrapping inSome, matching the updated type signature.src/handlers/http/middleware.rs (1)
185-185: LGTM! Simplified OIDC client retrieval.src/handlers/http/oidc.rs (3)
83-83: LGTM! Simplified OIDC client retrieval.The direct
.get()call is cleaner than the previous pattern matching approach.
149-165: LGTM! Clearer logout endpoint extraction.The explicit if-let pattern for extracting the logout endpoint improves readability compared to nested pattern matching.
180-184: LGTM! Simplified client retrieval with early return.The explicit if-let with early return for unauthorized is clearer than nested pattern matching.
logout flow incorrectly assumed the oidc client to always be present
shifted sse handler from lazy to oncecell
Fixes #XXXX.
Description
This PR has:
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.