- Notifications
You must be signed in to change notification settings - Fork 726
fix(server): Fix the logic of the WithStateLess function #387
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(server): Fix the logic of the WithStateLess function #387
Conversation
Added a check for the stateLess parameter in the WithStateLess function. Only when stateLess is true, set the sessionIdManager to StatelessSessionIdManager. This modification ensures that the behavior of the WithStateLess function is consistent with expectations and improves the robustness of the code.
WalkthroughThe Changes
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File ( |
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)
server/streamable_http.go (1)
42-46: Consider explicitly restoring a stateful manager whenstateLessisfalse
Right now, callingWithStateLess(false)afterWithStateLess(true)(or after any other option that sets a stateless manager) will keep the previous stateless manager because theelsebranch is empty. That may surprise users who expectfalseto actively revert the server back to the default stateful behaviour, independent of option ordering.If you want
WithStateLessto be idempotent and self-contained, add an explicitelsebranch:return func(s *StreamableHTTPServer) { - if stateLess { - s.sessionIdManager = &StatelessSessionIdManager{} - } + if stateLess { + s.sessionIdManager = &StatelessSessionIdManager{} + } else { + // restore the default insecure stateful manager + s.sessionIdManager = &InsecureStatefulSessionIdManager{} + } }Alternatively, document that
falseis a no-op and that the final manager depends on option order.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
server/streamable_http.go(1 hunks)
🔇 Additional comments (1)
server/streamable_http.go (1)
43-45: Conditional assignment fix is spot-on – behaviour now matches thestateLessflag
The option no longer overrides the session manager whenstateLessisfalse, which was the root cause of the bug. ✅
Description
Added a check logic for the stateLess parameter in the WithStateLess function: Only when stateLess is true, set the sessionIdManager to StatelessSessionIdManager. This modification ensures that the function behaves as expected and improves the robustness of the code.
Summary by CodeRabbit