Skip to content

Commit a611742

Browse files
committed
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 Wei-Shaw#2310
1 parent 1879038 commit a611742

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

backend/internal/service/openai_images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ func (s *OpenAIGatewayService) forwardOpenAIImagesAPIKey(
639639
setOpsUpstreamRequestBody(c, forwardBody)
640640
}
641641

642-
upstreamCtx, releaseUpstreamCtx := detachStreamUpstreamContext(ctx, parsed.Stream)
642+
upstreamCtx, releaseUpstreamCtx := detachUpstreamContext(ctx)
643643
defer releaseUpstreamCtx()
644644

645645
token, _, err := s.GetAccessToken(upstreamCtx, account)

backend/internal/service/openai_images_responses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ func (s *OpenAIGatewayService) forwardOpenAIImagesOAuth(
948948
)
949949
}
950950

951-
upstreamCtx, releaseUpstreamCtx := detachStreamUpstreamContext(ctx, parsed.Stream)
951+
upstreamCtx, releaseUpstreamCtx := detachUpstreamContext(ctx)
952952
defer releaseUpstreamCtx()
953953

954954
token, _, err := s.GetAccessToken(upstreamCtx, account)

0 commit comments

Comments
 (0)