Skip to content

📝 [Proposal]: Revert of Reject Middleware context.Context PRs #3358

Closed
@sixcolors

Description

@sixcolors

Feature Proposal Description

We should Revert of Reject Middleware context.Context PRs.

Ref: #3339 #3340 #3364 #3365 #3175 #3287

If the goal is to make a service layer framework-agnostic, this approach does not achieve that.

These changes do not remove Fiber-specific dependencies—they add redundant storage without solving the actual issue. Instead of making middleware truly agnostic, they force extra overhead onto Fiber users and violate Fiber’s request-response model.


1. The Service Layer Still Needs Fiber-Specific Code

Even after these changes, the service layer still calls FromContext(), which now checks both fiber.Ctx and context.Context.

This means:

  • The service layer remains aware of Fiber's middleware, contradicting the goal of true framework-agnostic design.
  • Instead of cleanly separating concerns, this just adds another storage layer while keeping Fiber-specific logic.

🔹 A truly agnostic service layer would:
✅ Expect values only from context.Context, without needing Fiber-specific utilities.
Require the caller to store values in context.Context before calling the service layer.

These PRs do not fix the real problem—they just make it more convoluted.


2. Unnecessary Redundancy for Fiber Users

For Fiber users who do not use context.Context, these changes introduce pointless duplication:

  • Now, values are stored twice—once in Locals, once in context.Context.
  • Extra allocations are performed on every request, increasing memory and CPU usage.
  • Zero benefit for users who rely only on Fiber’s Locals.

Fiber’s Locals already provides efficient, request-scoped storage. If Fiber itself were designed around context.Context, this discussion would make sense—but that should be a framework-level decision, not a middleware-by-middleware patchwork.

🔴 The result?
❌ Unnecessary overhead for Fiber users.
❌ A second, redundant storage system that serves no real purpose.


3. This Is a Service Layer Problem, Not a Framework Problem

The root issue isn’t Fiber’s middleware—it’s how the service layer expects to retrieve values.

If a service layer is truly framework-agnostic, it should:
✅ Expect context.Context and rely on the caller to store values there before calling it.
✅ Avoid any framework-specific lookup functions.

Instead, these PRs try to bridge both worlds by keeping Fiber-specific lookups and adding a second storage mechanism, which helps neither case.


Conclusion: These PRs Should Be Reverted or Rejected

These PRs do not solve the problem—they just introduce inefficiency:

🛑 They fail to make the service layer framework-agnostic—Fiber-specific logic is still required.
🛑 They add redundant storage, increasing memory usage and allocations for no reason.
🛑 They break Fiber’s design principles by forcing a second, unnecessary request-scoped store.
🛑 If context.Context is truly needed, this should be addressed at the framework level, not middleware-by-middleware.

If we are serious about context.Context support in Fiber, we should focus on #3344 and consider a proper framework-level implementation, instead of merging piecemeal workarounds that introduce yet another redundant storage mechanism. As @pjebs said "Having too many different types of contexts is confusing".

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have searched for existing issues that describe my proposal before opening this one.
  • I understand that a proposal that does not meet these guidelines may be closed without explanation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions