autoresearch iter 4: stop one disconnected client from failing a shared image flight

EnsureCompressedImageCache passed the arriving caller's request context into
the singleflight body, which runs once for every concurrent requester of that
cache key. If the first client disconnected, gin canceled the context, the
shared generation aborted, and every follower received that failure and fell
back to the uncompressed original. Detach cancellation with
context.WithoutCancel so trace values still propagate but the shared work
outlives any single requester.
This commit is contained in:
ryan
2026-08-29 08:07:19 +08:00
parent 5b84fd906d
commit 7e6b9e7c2f
2 changed files with 53 additions and 2 deletions
@@ -227,8 +227,11 @@ func EnsureCompressedImageCache(
return nil, false, fmt.Errorf("read compressed image cache: %w", err)
}
// The flight body serves every concurrent requester for this key, so it must
// not die when whichever caller happened to arrive first disconnects.
flightCtx := context.WithoutCancel(ctx)
result, err, _ := compressedImageFlight.Do(cacheKey, func() (any, error) {
return generateCompressedImageCache(ctx, upload, quality, cacheKey)
return generateCompressedImageCache(flightCtx, upload, quality, cacheKey)
})
if err != nil {
return nil, false, err