🔥feat: Add storage backed SharedState for prefork applications#4243
🔥feat: Add storage backed SharedState for prefork applications#4243
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
WalkthroughIntroduces a new storage-backed Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 (2.11.4)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" 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. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4243 +/- ##
==========================================
- Coverage 91.26% 91.15% -0.11%
==========================================
Files 123 124 +1
Lines 11877 12253 +376
==========================================
+ Hits 10839 11169 +330
- Misses 653 679 +26
- Partials 385 405 +20
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces SharedState, a storage-backed state management system for Fiber designed to be safe for prefork workers and multi-process environments. It adds new configuration fields to Config, implements a variety of data access methods with support for multiple encoding formats (JSON, MsgPack, CBOR, XML), and provides comprehensive documentation and tests. Review feedback suggests removing a redundant string copy in the key generation logic and highlights potential concerns regarding key length and readability when using hex encoding.
There was a problem hiding this comment.
Pull request overview
Adds a new storage-backed SharedState API to Fiber apps to support prefork-safe / multi-process shared key–value state, with configurable namespacing and codec helpers aligned with app-configured encoders/decoders.
Changes:
- Introduces
SharedStatewith raw (Set/Get) and encoded (SetJSON/GetJSON,SetMsgPack/GetMsgPack,SetCBOR/GetCBOR,SetXML/GetXML) operations, plus context-aware variants. - Wires shared state into
AppviaConfig.SharedStorageandConfig.SharedStatePrefix, and exposesApp.SharedState()alongside clarifiedApp.State()semantics. - Adds documentation and a comprehensive unit test suite covering configuration, namespacing, context propagation, and error handling.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
shared_state.go |
Implements the SharedState API over fiber.Storage, including prefixing and codec helpers. |
app.go |
Adds shared-state configuration, initializes shared state in New(), and exposes App.SharedState(). |
shared_state_test.go |
Adds unit tests for shared-state behavior (storage config, namespacing, codecs, context, error propagation). |
docs/api/state.md |
Documents prefork-safe SharedState, configuration, method signatures, and examples. |
docs/api/app.md |
Updates app API docs to distinguish State() (process-local) vs SharedState() (storage-backed). |
docs/whats_new.md |
Notes SharedState as a new v3 app feature. |
There was a problem hiding this comment.
⚠️ 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: a72c503 | Previous: f6ecd99 | Ratio |
|---|---|---|---|
Benchmark_Compress_Levels/Zstd_LevelDefault (github.com/gofiber/fiber/v3/middleware/compress) - B/op |
1 B/op |
0 B/op |
+∞ |
This comment was automatically generated by workflow using github-action-benchmark.
Motivation
AppName) and reuse app-configured encoders/decoders for JSON/MsgPack/CBOR/XML.Description
SharedStateimplementation (shared_state.go) exposing raw and encoded helpers such asSet,Get,SetJSON,GetJSON,SetMsgPack,GetMsgPack,SetCBOR,GetCBOR,SetXML,GetXML,Delete,Has, and context-aware variants.SharedStateinto the app by addingConfig.SharedStorageandConfig.SharedStatePrefix, initializingapp.sharedStateinNew(...), and exposingApp.SharedState()while clarifying thatApp.State()remains process-local.defaultSharedStatePrefix+ optionalAppName) and ensure theSharedStateuses the app-provided encoder/decoder hooks.docs/api/app.md,docs/api/state.md,docs/whats_new.md) and add comprehensive unit tests inshared_state_test.gocovering configuration, context propagation, serialization, codec usage, namespacing, and error propagation.