mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
fix(gateway): detach upstream context unconditionally for image generation
Image generation requests (forwardOpenAIImagesOAuth and forwardOpenAIImagesAPIKey) were calling detachStreamUpstreamContext with parsed.Stream, which for non-streaming requests (Stream=false) simply returned the original client context unchanged. When the client disconnected before the upstream completed (30-80s for image gen), the context cancellation propagated to the upstream HTTP request, causing a 502 error despite the upstream having already started processing. Switch to detachUpstreamContext (unconditional detach) so the upstream image generation request is always bound to a background context and completes regardless of client lifecycle. Fixes #2310
This commit is contained in:
@@ -639,7 +639,7 @@ func (s *OpenAIGatewayService) forwardOpenAIImagesAPIKey(
|
||||
setOpsUpstreamRequestBody(c, forwardBody)
|
||||
}
|
||||
|
||||
upstreamCtx, releaseUpstreamCtx := detachStreamUpstreamContext(ctx, parsed.Stream)
|
||||
upstreamCtx, releaseUpstreamCtx := detachUpstreamContext(ctx)
|
||||
defer releaseUpstreamCtx()
|
||||
|
||||
token, _, err := s.GetAccessToken(upstreamCtx, account)
|
||||
|
||||
@@ -948,7 +948,7 @@ func (s *OpenAIGatewayService) forwardOpenAIImagesOAuth(
|
||||
)
|
||||
}
|
||||
|
||||
upstreamCtx, releaseUpstreamCtx := detachStreamUpstreamContext(ctx, parsed.Stream)
|
||||
upstreamCtx, releaseUpstreamCtx := detachUpstreamContext(ctx)
|
||||
defer releaseUpstreamCtx()
|
||||
|
||||
token, _, err := s.GetAccessToken(upstreamCtx, account)
|
||||
|
||||
Reference in New Issue
Block a user