-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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(middleware/session): mutex for thread safety #3050
Conversation
WalkthroughThese changes focus on refactoring and optimizing the session management in the Changes
Poem
Tip Early access features: enabledWe are currently testing the following features in early access:
Note:
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configration 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
Outside diff range and nitpick comments (1)
middleware/session/session_test.go (1)
Line range hint
536-536
: Remove unused variable.The variable
originalSessionUUIDString
is assigned but never used.- originalSessionUUIDString := ""
Also applies to: 602-602
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- middleware/session/session.go (1 hunks)
- middleware/session/session_test.go (2 hunks)
- middleware/session/store.go (1 hunks)
Additional context used
golangci-lint
middleware/session/session_test.go
536-536: assigned to originalSessionUUIDString, but reassigned without using the value
(wastedassign)
602-602: assigned to originalSessionUUIDString, but reassigned without using the value
(wastedassign)
Additional comments not posted (3)
middleware/session/session.go (1)
280-288
: Refactor error handling for better readability.The error check can be simplified for better readability.
- if err := encCache.Decode(&s.data.Data); err != nil { - return fmt.Errorf("failed to decode session data: %w", err) - } + if err := encCache.Decode(&s.data.Data); err != nil { + return fmt.Errorf("failed to decode session data: %w", err) + } return nilLikely invalid or redundant comment.
middleware/session/session_test.go (2)
4-5
: LGTM!
680-719
: Add assertions in the parallel benchmark.Consider adding assertions to validate the benchmark results.
- b.Run("default", func(b *testing.B) { + b.Run("default_asserted", func(b *testing.B) {Likely invalid or redundant comment.
@sixcolors i don't see any mutex adjustments? |
It seems I messed up the merge, give me a couple of minutes to fix the PR. |
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
Outside diff range and nitpick comments (2)
middleware/session/session_test.go (2)
Line range hint
536-536
: Remove the wasted assignment.The assignment to
originalSessionUUIDString
before reassignment is unnecessary and can be removed.- originalSessionUUIDString := ""
Line range hint
602-602
: Remove the wasted assignment.The assignment to
originalSessionUUIDString
before reassignment is unnecessary and can be removed.- originalSessionUUIDString := ""
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- middleware/session/session.go (10 hunks)
- middleware/session/session_test.go (2 hunks)
- middleware/session/store.go (3 hunks)
Files skipped from review as they are similar to previous changes (2)
- middleware/session/session.go
- middleware/session/store.go
Additional context used
golangci-lint
middleware/session/session_test.go
536-536: assigned to originalSessionUUIDString, but reassigned without using the value
(wastedassign)
602-602: assigned to originalSessionUUIDString, but reassigned without using the value
(wastedassign)
Additional comments not posted (3)
middleware/session/session_test.go (3)
4-5
: LGTM!The imports for
errors
andsync
are necessary for the new concurrency tests.
760-799
: LGTM!The
Benchmark_Session_Asserted_Parallel
function includes necessary assertions and sets up parallel benchmarks correctly.
801-904
: LGTM!The
Test_Session_Concurrency
function sets up concurrent goroutines to test session operations and includes necessary error handling and assertions.
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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- middleware/session/store.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- middleware/session/store.go
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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- middleware/session/session.go (10 hunks)
Files skipped from review as they are similar to previous changes (1)
- middleware/session/session.go
@ReneWerner87 ready |
* chore: Remove extra release and acquire ctx calls in session_test.go * feat: Remove unnecessary session mutex lock in decodeSessionData function * chore: Refactor session benchmark tests * fix(middleware/session): mutex for thread safety * feat: Add session mutex lock for thread safety * chore: Refactor releaseSession mutex
This pull request adds a mutex to the session middleware to ensure thread safety when accessing session data. The mutex is used to protect non-data fields and prevent race conditions. This improves the reliability and stability of the session middleware.