Skip to content

🐛 fix: implement releaseData function for better resource management - #4209

Merged
ReneWerner87 merged 4 commits into
mainfrom
fix_session_release_flaky_tests
Apr 11, 2026
Merged

ReneWerner87 merged 4 commits into
mainfrom
fix_session_release_flaky_tests

Conversation

@ReneWerner87

Copy link
Copy Markdown
Member

No description provided.

@ReneWerner87
ReneWerner87 requested a review from a team as a code owner April 11, 2026 18:49
@ReneWerner87
ReneWerner87 requested review from Copilot, efectn, gaby and sixcolors and removed request for Copilot April 11, 2026 18:49
@ReneWerner87 ReneWerner87 added this to v3 Apr 11, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone Apr 11, 2026
@coderabbitai

coderabbitai Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Added a nil-safe package helper releaseData(d *data) that resets a *data and returns it to the package dataPool. Updated session data tests to centralize teardown by deferring releaseData(...) instead of manually calling d.Reset() and dataPool.Put(d).

Changes

Cohort / File(s) Summary
Data Pool Helper
middleware/session/data.go
Added func releaseData(d *data) which is nil-safe, calls d.Reset() when non-nil, and returns the instance to the package dataPool via dataPool.Put(d).
Session Data Tests
middleware/session/data_test.go
Refactored test teardowns to use defer releaseData(...) across subtests; removed explicit d.Reset()/dataPool.Put(...) pairs and adjusted a few acquisitions/releases (replaced acquireWithCleanup() with acquireData() where appropriate).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hop and nudge the pooled cache light,
A tidy reset, returned just right.
Tests sleep sound with cleaner ends,
One small helper, no loose threads.
✨ Hop—release, and all is bright.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request has no description provided by the author, leaving all required template sections empty. Add a comprehensive description following the repository template, including problem statement, changes introduced, type of change, and completion of the provided checklist items.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title indicates a bug fix with a new function but doesn't specify what the actual issue is or which component benefits from this change.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix_session_release_flaky_tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a releaseData helper function to centralize the resetting and pooling of session data, with corresponding updates across the test suite. Feedback suggests that setting s.data to nil in releaseSession may introduce concurrency risks and performance regressions. Additionally, the reviewer identified redundant Reset calls in the session acquisition logic and tests that can be removed now that releaseData handles the reset process.

Comment thread middleware/session/session.go Outdated
Comment thread middleware/session/data.go
Comment thread middleware/session/data_test.go
Comment thread middleware/session/data.go
@codecov

codecov Bot commented Apr 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.18%. Comparing base (6c19f48) to head (99bb57a).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
middleware/session/data.go 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4209      +/-   ##
==========================================
+ Coverage   91.16%   91.18%   +0.02%     
==========================================
  Files         123      123              
  Lines       11855    11860       +5     
==========================================
+ Hits        10808    10815       +7     
+ Misses        659      656       -3     
- Partials      388      389       +1     
Flag Coverage Δ
unittests 91.18% <60.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@middleware/session/data_test.go`:
- Around line 215-218: The test currently returns the same pooled *data twice —
once via the acquired cleanup slice and again explicitly when releasing first —
which can double-put the same pointer into sync.Pool; update the test so each
pointer is released exactly once: either remove the explicit call that returns
first (referencing the variable first) or remove first from the acquired slice
before calling releaseData(first), ensuring the cleanup loop over acquired and
the releaseData(...) helper are the only places that return items to the pool.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 81b2cca8-b876-4caf-a0fd-43c7cf2150b2

📥 Commits

Reviewing files that changed from the base of the PR and between 6c19f48 and 37c19c2.

📒 Files selected for processing (3)
  • middleware/session/data.go
  • middleware/session/data_test.go
  • middleware/session/session.go

Comment thread middleware/session/data_test.go
Copilot AI review requested due to automatic review settings April 11, 2026 19:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a small pooling helper to centralize returning session.data instances to sync.Pool, and updates the session data unit tests to use it for simpler, more consistent cleanup.

Changes:

  • Introduce releaseData(*data) to reset and return data objects to dataPool.
  • Refactor middleware/session/data_test.go to replace manual Reset() + dataPool.Put() sequences with releaseData().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
middleware/session/data.go Adds releaseData helper for returning pooled data instances.
middleware/session/data_test.go Simplifies test cleanup by using releaseData consistently.

Comment thread middleware/session/data.go
Comment thread middleware/session/data_test.go

@gaby gaby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@gaby gaby changed the title fix: implement releaseData function for better resource management 🐛 fix: implement releaseData function for better resource management Apr 11, 2026
@ReneWerner87
ReneWerner87 merged commit c9f3475 into main Apr 11, 2026
20 of 21 checks passed
@github-project-automation github-project-automation Bot moved this to Done in v3 Apr 11, 2026
@ReneWerner87
ReneWerner87 deleted the fix_session_release_flaky_tests branch April 11, 2026 19:37

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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: 0a7fd68 Previous: 6c19f48 Ratio
Benchmark_FiberHandlerFunc/25MB (github.com/gofiber/fiber/v3/middleware/adaptor) 5296 ns/op 33148 B/op 8 allocs/op 3296 ns/op 33117 B/op 8 allocs/op 1.61
Benchmark_FiberHandlerFunc/25MB (github.com/gofiber/fiber/v3/middleware/adaptor) - ns/op 5296 ns/op 3296 ns/op 1.61

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

@ReneWerner87 ReneWerner87 modified the milestones: v3, v3.2.0 Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants