Skip to content

📒 docs: thread-safety contracts for mutex-backed public types#4367

Merged
ReneWerner87 merged 3 commits into
mainfrom
copilot/add-thread-safety-documentation
May 28, 2026
Merged

📒 docs: thread-safety contracts for mutex-backed public types#4367
ReneWerner87 merged 3 commits into
mainfrom
copilot/add-thread-safety-documentation

Conversation

Copilot AI commented May 28, 2026

Copy link
Copy Markdown
Contributor

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.

  • Public API docs
    • Add thread-safety statements to App, Client, CookieJar, Stream, MemoryLock, and both in-memory Storage implementations.
  • Qualified concurrency guidance
    • Clarify that Client is safe for concurrent request execution after configuration is complete, that CookieJar.Release must not run concurrently with other methods, and that internal/storage/memory.Storage.Conn() returns a live shared map that still requires external synchronization.
  • Session lifecycle clarity
    • Clarify that session.Session and session.Middleware synchronize internal state, but remain request-scoped and must not outlive the request lifecycle.
  • App-specific caveat
    • Document App as concurrent-safe while preserving the existing exception for route mutation APIs that explicitly document otherwise.

Example of the updated contract style:

// App denotes the Fiber application.
// App is safe for concurrent use, except for route mutation methods that
// explicitly document otherwise.
type App struct { ... }

Changes introduced

  • Benchmarks: No performance changes.
  • Documentation Update: Added thread-safety and lifecycle guidance to the affected Go type doc comments in 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, and internal/storage/memory/memory.go, including qualified caveats where blanket concurrency guarantees would be inaccurate.
  • Changelog/What's New: Not applicable.
  • Migration Guide: Not applicable.
  • API Alignment with Express: Not applicable.
  • API Longevity: Clarifies existing concurrency behavior without changing APIs or semantics, and narrows the affected contracts where external synchronization is still required.
  • Examples: Inline doc-comment examples only.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Enhancement (improvement to existing features and functionality)
  • Documentation update (changes to documentation)
  • Performance improvement (non-breaking change which improves efficiency)
  • Code consistency (non-breaking change which improves code reliability and robustness)

Checklist

Before you submit your pull request, please make sure you meet these requirements:

  • Followed the inspiration of the Express.js framework for new functionalities, making them similar in usage.
  • Conducted a self-review of the code and provided comments for complex or critical parts.
  • Updated the documentation in the /docs/ directory for Fiber's documentation.
  • Added or updated unit tests to validate the effectiveness of the changes or new features.
  • Ensured that new and existing unit tests pass locally with the changes.
  • Verified that any new dependencies are essential and have been agreed upon by the maintainers/community.
  • Aimed for optimal performance with minimal allocations in the new code.
  • Provided benchmarks for the new code to analyze and improve upon.

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

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
Copilot AI requested a review from gaby May 28, 2026 04:29
Copilot finished work on behalf of gaby May 28, 2026 04:29
@gaby gaby changed the title Document thread-safety contracts for mutex-backed public types 📒 docs: thread-safety contracts for mutex-backed public types May 28, 2026
@ReneWerner87 ReneWerner87 added this to v3 May 28, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone May 28, 2026
@gaby gaby marked this pull request as ready for review May 28, 2026 04:34
@gaby gaby requested a review from a team as a code owner May 28, 2026 04:34
@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.39%. Comparing base (e5e93e6) to head (bb47e07).

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           
Flag Coverage Δ
unittests 91.39% <ø> (ø)

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.

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 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 Stream and idempotency MemoryLock.

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.

Comment thread client/cookiejar.go
Comment thread client/client.go
Comment thread internal/storage/memory/memory.go Outdated
Copilot finished work on behalf of gaby May 28, 2026 04:48
Copilot AI requested a review from gaby May 28, 2026 04:48
@ReneWerner87 ReneWerner87 merged commit 2bcc221 into main May 28, 2026
21 checks passed
@ReneWerner87 ReneWerner87 deleted the copilot/add-thread-safety-documentation branch May 28, 2026 05:30
@github-project-automation github-project-automation Bot moved this to Done in v3 May 28, 2026
@ReneWerner87 ReneWerner87 modified the milestones: v3, v3.4.0 Jul 2, 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.

🧹 [Maintenance]: add thread-safety documentation to public types with mutexes

4 participants