📒 docs: thread-safety contracts for mutex-backed public types#4367
Merged
Conversation
Copilot
AI
changed the title
[WIP] Add thread-safety documentation to public types with mutexes
Document thread-safety contracts for mutex-backed public types
May 28, 2026
gaby
approved these changes
May 28, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4367 +/- ##
=======================================
Coverage 91.39% 91.39%
=======================================
Files 132 132
Lines 13098 13098
=======================================
Hits 11971 11971
Misses 710 710
Partials 417 417
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:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds explicit thread-safety and lifecycle contracts to doc comments for several mutex-backed (or otherwise synchronized) types so users can better understand which APIs are safe to share across goroutines vs. request-scoped objects.
Changes:
- Document concurrency guarantees for core/public types (e.g.,
App,Client,CookieJar) and selected middleware/internal utilities. - Clarify session middleware lifecycle expectations (request-scoped; not valid beyond request end).
- Add concurrency statement for SSE
Streamand idempotencyMemoryLock.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| app.go | Documents App’s intended concurrency contract with route-mutation caveat. |
| client/client.go | Adds a concurrency statement for Client (needs tighter wording to match implementation). |
| client/cookiejar.go | Adds a concurrency statement for CookieJar (needs qualification re: Release). |
| internal/memory/memory.go | States in-memory test/benchmark storage is concurrent-safe. |
| internal/storage/memory/memory.go | States test storage is concurrent-safe (needs qualification due to Conn() exposing the map). |
| middleware/idempotency/locker.go | Documents MemoryLock as concurrent-safe. |
| middleware/session/session.go | Clarifies Session is mutex-protected but request-scoped. |
| middleware/session/middleware.go | Clarifies Middleware is mutex-protected but request-scoped. |
| middleware/sse/sse.go | Documents SSE Stream as concurrent-safe. |
gaby
approved these changes
May 28, 2026
ReneWerner87
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Several public types use internal synchronization but did not state their concurrency guarantees in the API surface. This change adds explicit thread-safety guidance to those type comments so users can distinguish concurrent-safe types from request-scoped/session-scoped objects, while documenting the cases where external synchronization is still required.
App,Client,CookieJar,Stream,MemoryLock, and both in-memoryStorageimplementations.Clientis safe for concurrent request execution after configuration is complete, thatCookieJar.Releasemust not run concurrently with other methods, and thatinternal/storage/memory.Storage.Conn()returns a live shared map that still requires external synchronization.session.Sessionandsession.Middlewaresynchronize internal state, but remain request-scoped and must not outlive the request lifecycle.Appas concurrent-safe while preserving the existing exception for route mutation APIs that explicitly document otherwise.Example of the updated contract style:
Changes introduced
app.go,client/client.go,client/cookiejar.go,middleware/session/session.go,middleware/session/middleware.go,middleware/sse/sse.go,middleware/idempotency/locker.go,internal/memory/memory.go, andinternal/storage/memory/memory.go, including qualified caveats where blanket concurrency guarantees would be inaccurate.Type of change
Please delete options that are not relevant.
Checklist
Before you submit your pull request, please make sure you meet these requirements:
/docs/directory for Fiber's documentation.Commit formatting
Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. Check out the emoji cheatsheet here: CONTRIBUTING.md