stability: propagate request context end-to-end #6

Open
opened 2026-05-23 18:30:28 +00:00 by Klaus · 0 comments
Owner

Problem

Tool handlers receive a context.Context from the MCP frame but most operation modules ignore it — they construct a fresh Gitea SDK client (with its own 60s timeout in pkg/gitea/rest.go) and call methods that don't take a context. As a result:

  • An HTTP client that disconnects mid-call cannot cancel the upstream Gitea request
  • Graceful shutdown (10s timeout in operation/operation.go) only stops accepting new connections; in-flight tool calls continue
  • Per-request deadlines aren't honored

Suggested direction

  • Where the SDK exposes *Ctx variants, switch to them and pass the handler's ctx
  • Where the SDK does not, wrap the client's http.Client Transport with one that watches ctx.Done() and aborts the request
  • Set a sensible per-call deadline (e.g. 30s) derived from the parent context
  • Verify graceful shutdown actually cancels in-flight work
## Problem Tool handlers receive a `context.Context` from the MCP frame but most operation modules ignore it — they construct a fresh Gitea SDK client (with its own 60s timeout in `pkg/gitea/rest.go`) and call methods that don't take a context. As a result: - An HTTP client that disconnects mid-call cannot cancel the upstream Gitea request - Graceful shutdown (10s timeout in `operation/operation.go`) only stops accepting new connections; in-flight tool calls continue - Per-request deadlines aren't honored ## Suggested direction - Where the SDK exposes `*Ctx` variants, switch to them and pass the handler's `ctx` - Where the SDK does not, wrap the client's `http.Client` `Transport` with one that watches `ctx.Done()` and aborts the request - Set a sensible per-call deadline (e.g. 30s) derived from the parent context - Verify graceful shutdown actually cancels in-flight work
Klaus referenced this issue from a commit 2026-05-23 18:47:28 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Klaus/gitea-mcp#6