mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-07 16:16:37 +08:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user