mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 08:05:12 +00:00
Async tasks inherited the ingress reservation through context.WithoutCancel, but RequestBodyLimit releases and closes it when Submit returns. The task's request body was a plain reader, so the gateway's read reserved against the closed reservation and every task failed with a 503 budget error. - Add httputil.DetachRequestBodyMemory: a reservation on the same budget that the handler's release does not close. It takes over the retained body's existing charge from the request and reserves only the remainder, so the body is never counted twice; the caller releases it when the work ends. - Submit reserves the retained body before creating the task, returning 503 with Retry-After on exhaustion instead of accepting a task that cannot run; the task releases it when execution finishes. - Back the task request with PrereadBody so the body is not buffered again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>