Avoid creating sessions during invalidate - #15813
Conversation
Update GrailsHttpSession.invalidate() so it invalidates an existing servlet session without creating one when none exists. Add regression coverage for both no-session and existing-session wrapper paths. Assisted-by: Hephaestus:gpt-5.5 review-gate codex-review
There was a problem hiding this comment.
Pull request overview
This PR adjusts GrailsHttpSession.invalidate() so it no longer forces creation of a servlet HttpSession when none exists, while still ensuring that an already-existing request session can be invalidated even if the wrapper was never accessed. This aligns invalidation behavior with “don’t create on invalidate” expectations and adds a regression spec in grails-web-common to prevent regressions.
Changes:
- Update
GrailsHttpSession.invalidate()to userequest.getSession(false)(no-create) and only invalidate when a session actually exists. - Ensure wrapper invalidation semantics remain consistent when an existing request session is invalidated before any wrapper access.
- Add
GrailsHttpSessionSpeccoverage for both “no existing session” and “existing session” invalidation paths.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| grails-web-common/src/main/groovy/grails/web/servlet/mvc/GrailsHttpSession.java | Stops invalidate() from creating a servlet session; invalidates only if an existing session is present (wrapper or request). |
| grails-web-common/src/test/groovy/grails/web/servlet/mvc/GrailsHttpSessionSpec.groovy | Adds regression tests validating non-creation on invalidate and correct invalidation behavior when a request session already exists. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🚨 TestLens detected 1 failed test 🚨Here is what you can do:
Test SummaryCI / Functional Tests (Java 21, indy=true) > :grails-test-examples-app1:integrationTest
🏷️ Commit: a812020 Test FailuresForwardingSpec > Test forwarding to an action which returns a Map (:grails-test-examples-app1:integrationTest in CI / Functional Tests (Java 21, indy=true))Muted TestsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #15813 +/- ##
==================================================
+ Coverage 49.4842% 49.4912% +0.0070%
- Complexity 16697 16701 +4
==================================================
Files 1947 1947
Lines 92474 92477 +3
Branches 16152 16154 +2
==================================================
+ Hits 45760 45768 +8
+ Misses 39606 39602 -4
+ Partials 7108 7107 -1
🚀 New features to boost your workflow:
|
Summary
Verification
.\\gradlew.bat --no-daemon --no-parallel --max-workers=1 :grails-web-common:test --tests "grails.web.servlet.mvc.GrailsHttpSessionSpec"81bc27b564a1b4dc3e0d900a1d56aaae6519941bNotes