Repository navigation
Always signal S3 upload completion so failed uploads don't hang the handler - #72
Merged
Merged
Conversation
jtomson
marked this pull request as ready for review
November 3, 2026 19:59
…andler Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jtomson
force-pushed
the
fix-s3-upload-hang
branch
from
November 3, 2026 20:02
7b22a38 to
33881e6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
uploadToS3 only sent on the uploaded channel when PutObject succeeded. If the session or the upload failed it returned without sending, and the processing handler waited on <-uploaded forever after it had already written the image to the client.
Each stuck handler keeps its processing semaphore token (released by a defer at processing_handler.go:302) and its queue token, so every failed upload permanently takes one of the IMGPROXY_WORKERS slots. With the default of GOMAXPROCS x 2, a handful of S3 errors (expired credentials, throttling, an outage) leaves the instance unable to render anything until it restarts. Cached images still serve from S3/CloudFront, so it shows up as new renders stalling.
The send now happens in a defer with the upload result, and the channel is buffered so the goroutine can't block either.
How I tested it
Added TestBeforeResponseSignalsOnUploadFailure, which forces PutObject to fail validation locally (empty bucket, no network) and waits up to 10s for the channel.
Before the fix it fails at the 10s timeout. After the fix it passes, and go test . passes.
🤖 Generated with Claude Code