Skip to content

fix: [#676] Unnecessary Redis connection attempt on startup despite SESSION_DRIVER=file#1043

Merged
hwbrzzl merged 5 commits intomasterfrom
bowen/#676
May 24, 2025
Merged

fix: [#676] Unnecessary Redis connection attempt on startup despite SESSION_DRIVER=file#1043
hwbrzzl merged 5 commits intomasterfrom
bowen/#676

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented May 19, 2025

📑 Description

Closes goravel/goravel#676

The root reason is that the redis driver is initialized even if the session driver is file. We cancel the initial process in this PR.

This pull request refactors the session management system to simplify configuration handling, improve driver registration, and update related tests. Key changes include replacing dynamic configuration lookups with cached properties, removing unused methods, and updating tests to align with the new implementation.

image

Refactoring of session management:

  • Removed the Extend method from the Manager interface and its implementation, simplifying the driver registration process. (contracts/session/manager.go, session/manager.go) [1] [2]
  • Cached configuration values (cookie, defaultDriver, gcInterval, lifetime) as properties in the Manager struct to reduce repeated lookups. (session/manager.go)
  • Replaced getDefaultDriver and registerConfiguredDrivers methods with a streamlined registerDriver method for registering individual drivers. (session/manager.go) [1] [2]

Updates to session behavior:

  • Updated the BuildSession method to use the cached cookie property instead of fetching it dynamically. (session/manager.go)
  • Simplified garbage collection timer setup by using the cached gcInterval and lifetime properties. (session/manager.go)

Improvements to tests:

  • Replaced dynamic mock expectations with explicit calls to EXPECT() for better test reliability and readability. (session/manager_test.go, session/middleware/start_session_test.go) [1] [2]
  • Removed outdated test cases for deprecated methods like Extend and getDefaultDriver. (session/manager_test.go)
  • Updated test cases to align with the new driver registration and configuration handling approach. (session/manager_test.go, session/middleware/start_session_test.go) [1] [2]

Middleware adjustments:

  • Updated the StartSession middleware to use default values for session.lifetime if not explicitly provided. (session/middleware/start_session.go)

✅ Checks

  • Added test cases for my code

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 5197b21 Previous: 88c15e8 Ratio
BenchmarkSession_ManagerInteraction 537.6 ns/op 240 B/op 5 allocs/op null ns/op 0 B/op 0 allocs/op +∞
BenchmarkSession_ManagerInteraction - ns/op 537.6 ns/op null ns/op +∞
BenchmarkSession_ManagerInteraction - B/op 240 B/op 0 B/op +∞
BenchmarkSession_ManagerInteraction - allocs/op 5 allocs/op 0 allocs/op +∞

This comment was automatically generated by workflow using github-action-benchmark.

// Driver retrieves the session driver by name.
Driver(name ...string) (Driver, error)
// Extend extends the session manager with a custom driver.
Extend(driver string, handler func() Driver) error
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Extend method should extend driver type: file, custom instead of a specific driver(current logic), so remove it for now, user should use the custom driver to extend custom handler.

@codecov
Copy link

codecov bot commented May 23, 2025

Codecov Report

Attention: Patch coverage is 89.13043% with 5 lines in your changes missing coverage. Please review.

Project coverage is 70.54%. Comparing base (41f87c3) to head (e241816).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
session/manager.go 88.88% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1043      +/-   ##
==========================================
+ Coverage   70.49%   70.54%   +0.04%     
==========================================
  Files         176      176              
  Lines       12343    12330      -13     
==========================================
- Hits         8701     8698       -3     
+ Misses       3261     3252       -9     
+ Partials      381      380       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hwbrzzl hwbrzzl marked this pull request as ready for review May 23, 2025 08:51
@hwbrzzl hwbrzzl requested a review from a team as a code owner May 23, 2025 08:51
@hwbrzzl hwbrzzl merged commit fe01698 into master May 24, 2025
12 of 14 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#676 branch May 24, 2025 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unnecessary Redis connection attempt on startup despite SESSION_DRIVER=file

1 participant