Skip to content

📚 Doc: correct fasthttpctx Done semantics in context guide#4264

Merged
ReneWerner87 merged 1 commit into
gofiber:mainfrom
gtoxlili:fix/context-docs-disconnect
May 9, 2026
Merged

📚 Doc: correct fasthttpctx Done semantics in context guide#4264
ReneWerner87 merged 1 commit into
gofiber:mainfrom
gtoxlili:fix/context-docs-disconnect

Conversation

@gtoxlili
Copy link
Copy Markdown

@gtoxlili gtoxlili commented May 9, 2026

Description

The "Working with RequestCtx and fasthttpctx" section in docs/guide/context.md (introduced in #3677) currently tells readers that RequestCtx.Done closes when the client connection ends and that "handlers can detect client disconnects" via this channel. That is not what fasthttp actually does:

So the docs paragraph contradicts (a) the fasthttp source code, (b) two upstream fasthttp maintainers, (c) a four-year-old Fiber maintainer Q&A answer, and (d) an open Fiber proposal asking for the very capability the docs claim is already there.

Fixes #4263

Changes introduced

Three spots in docs/guide/context.md:

  1. The fasthttpctx paragraph (~L100): now describes the actual semantics (server-shutdown-only, shared channel, no client-disconnect signal) and points readers to context.WithTimeout or Flush-error detection for long handlers.
  2. The "Context Cancellation with Goroutines" paragraph (~L219): drops the misleading "or the client disconnects" phrasing and clarifies that the timeout (not a client-side cancellation) is what bounds the work.
  3. The Summary bullet (~L263): matches the corrected description.

No code changes; no API changes.

  • Benchmarks: n/a
  • Documentation Update: docs/guide/context.md — three passages corrected, no new sections.
  • Changelog/What's New: n/a (corrects an inaccurate claim, no behavior change)
  • Migration Guide: n/a
  • API Alignment with Express: n/a
  • API Longevity: n/a (docs only)
  • Examples: n/a

Type of change

  • Documentation update (changes to documentation)

Checklist

  • Conducted a self-review of the changes.
  • Updated the documentation in the /docs/ directory.
  • Added or updated unit tests — n/a, docs only.
  • Verified the wording against the fasthttp source and the linked issues.

@gtoxlili gtoxlili requested a review from a team as a code owner May 9, 2026 10:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d16e6ea9-e545-4592-9df4-a5ab5784a3ab

📥 Commits

Reviewing files that changed from the base of the PR and between 7a5eb8a and e1af685.

📒 Files selected for processing (1)
  • docs/guide/context.md
✅ Files skipped from review due to trivial changes (1)
  • docs/guide/context.md

Walkthrough

Documentation updates to Fiber's context guide clarifying that RequestCtx.Done() is a shared server-wide channel closing only on server shutdown, not client disconnect. Deadline remains a no-op. Async goroutine guidance and summary bullets are updated to match.

Changes

Context Semantics Clarification

Layer / File(s) Summary
RequestCtx Semantics
docs/guide/context.md
Core documentation of fasthttpctx behavior corrected: Done is shared across all in-flight requests and closes only on server shutdown, not individual client disconnects; Deadline is no-op; Err returns context.Canceled after shutdown.
Async Goroutine Guidance
docs/guide/context.md
Updated goroutine-in-Fiber cancellation guidance to emphasize exiting early on deadlines/timeouts (use context.WithTimeout) because fasthttp does not surface client disconnects via RequestCtx.Done.
Summary Bullets
docs/guide/context.md
Updated summary statement that RequestCtx.Done is shared across in-flight requests and closes only on server shutdown, matching the clarified semantics.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • gofiber/fiber#3729: Related docs updates describing fiber.Ctx context behavior and Deadline/Done/Err semantics.
  • gofiber/fiber#3884: Modifies the same context guide with examples and guidance for goroutine cancellation using derived contexts.
  • gofiber/fiber#3677: Prior PR that updated the context guide's RequestCtx.Done semantics; directly related.

Suggested reviewers

  • gaby
  • sixcolors
  • ReneWerner87
  • efectn

Poem

🐰 I hopped through docs to clear the air,
Done stays shared — no single-client scare.
Deadline sleeps, Err wakes on shutdown's bell,
Timeouts bound the work so handlers well.
Hooray — the guide now tells the truth so fair.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the change as a documentation correction to fasthttp Done semantics in the context guide.
Description check ✅ Passed The PR description is comprehensive, provides clear context from linked issue #4263, explains the three locations updated, and includes proper checklist completion.
Linked Issues check ✅ Passed The PR fully addresses the objective of #4263 by correcting documentation to accurately reflect fasthttp's server-wide Done semantics and recommending alternatives for timeout/disconnect detection.
Out of Scope Changes check ✅ Passed All changes are limited to correcting documentation in docs/guide/context.md to match the stated objective of fixing inaccurate Done semantics claims; no code or API changes are introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

Copy link
Copy Markdown
Contributor

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

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 updates the documentation to clarify that Fiber's underlying fasthttp context does not signal client disconnects through the Done channel, which instead only closes during server shutdown. The feedback suggests improving the consistency of external issue links, clarifying the usage of w.Flush() within StreamWriter, and recommending c.RequestCtx() as a parent context for timeouts to ensure server shutdown signals are properly propagated to goroutines.

Comment thread docs/guide/context.md Outdated
Comment on lines +107 to +108
provided by `fasthttp` (see [valyala/fasthttp#468](https://github.com/valyala/fasthttp/issues/468)
and [#965](https://github.com/valyala/fasthttp/issues/965), and the
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.

medium

For consistency and clarity, the second issue reference should include the repository name, as it refers to an external repository (valyala/fasthttp).

Suggested change
provided by `fasthttp` (see [valyala/fasthttp#468](https://github.com/valyala/fasthttp/issues/468)
and [#965](https://github.com/valyala/fasthttp/issues/965), and the
provided by fasthttp (see [valyala/fasthttp#468](https://github.com/valyala/fasthttp/issues/468)
and [valyala/fasthttp#965](https://github.com/valyala/fasthttp/issues/965), and the

Comment thread docs/guide/context.md Outdated
Comment on lines +111 to +112
the section below) or fall back to detecting failed `w.Flush()` writes on
streaming responses.
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.

medium

The mention of w.Flush() might be ambiguous for users unfamiliar with fasthttp's streaming implementation. It would be clearer to specify that this detection typically occurs within a StreamWriter (e.g., via c.Response().SetBodyStreamWriter) where the *bufio.Writer is available.

Comment thread docs/guide/context.md Outdated
Comment on lines +228 to +230
Note that `fasthttp` does not surface client disconnects through the request
context, so the timeout (not a client-side cancellation signal) is what bounds
the work here.
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.

medium

While it is correct that client disconnects are not surfaced, the server shutdown signal (from c.RequestCtx().Done()) is available. To ensure goroutines also terminate during a graceful server shutdown, it is recommended to use c.RequestCtx() as the parent context for context.WithTimeout. The current examples (like the one on line 241) use c.Context(), which defaults to context.Background() and does not honor the shutdown signal.

@gaby
Copy link
Copy Markdown
Member

gaby commented May 9, 2026

@gtoxlili Please fix the wording and tone of the changes. These are official docs, not a forum.

@gtoxlili gtoxlili force-pushed the fix/context-docs-disconnect branch from 211e0a9 to 7a5eb8a Compare May 9, 2026 11:23
@gtoxlili
Copy link
Copy Markdown
Author

gtoxlili commented May 9, 2026

@gaby Tightened the wording — dropped the bold emphasis, the inline issue links, and the explanatory asides. Just states the actual semantics now and points to the timeout pattern below. PTAL.

The "Working with RequestCtx and fasthttpctx" section and the Summary
bullet claimed that `RequestCtx.Done` closes when the client connection
ends. That is not what fasthttp actually does — `s.done` is the shared
server-wide channel and only closes on `Server.Shutdown`. Per-connection
disconnect detection is not currently provided by fasthttp.

Sources:
- valyala/fasthttp `server.go` comment on `RequestCtx.Done`:
  "RequestCtx.s.done is only closed when the server is shutting down"
- valyala/fasthttp#468, gofiber#771, gofiber#965 — upstream maintainers confirm in-handler
  client disconnect detection is not supported
- gofiber#805 (Fenny: "not possible nor efficient with fasthttp
  sync.pool design") and gofiber#1718 (same Q&A, closed with the same answer)
- gofiber#4145 — open proposal asking for the very capability the
  docs already advertised

Updates three spots in docs/guide/context.md:
1. The fasthttpctx paragraph — now describes the actual semantics and
   points readers to timeout / Flush-based detection for long handlers.
2. The "Context Cancellation with Goroutines" paragraph — drops the
   misleading "client disconnects" phrasing.
3. The Summary bullet — matches the corrected description.

Fixes gofiber#4263
@gtoxlili gtoxlili force-pushed the fix/context-docs-disconnect branch from 7a5eb8a to e1af685 Compare May 9, 2026 11:26
@ReneWerner87 ReneWerner87 merged commit db1fe20 into gofiber:main May 9, 2026
6 checks passed
@welcome
Copy link
Copy Markdown

welcome Bot commented May 9, 2026

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@github-project-automation github-project-automation Bot moved this to Done in v3 May 9, 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.

🐛 [Bug]: docs claim RequestCtx.Done closes on client disconnect, but it only closes on server shutdown

4 participants