fix: an interrupted upload stops holding the pending cap after 20 idle minutes; a dropped part goes again, quiet 429s, one Sentry report (DTF-WEB-13/14/15)
All checks were successful
Build and deploy / Validate source (push) Successful in 1m7s
Build and deploy / Integration suite on a real stack (push) Successful in 8m2s
Build and deploy / Secret scan and release gate (push) Successful in 10s
Build and deploy / Publish images (push) Successful in 1m35s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-24 17:17:31 -03:00
parent 242a56aae8
commit a1fad7698a
4 changed files with 31 additions and 9 deletions

View File

@@ -24,6 +24,10 @@ router = APIRouter()
# retrying must fit. The per-source bucket bounds abuse, not a real order.
UPLOAD_START_LIMIT = 1000
UPLOAD_START_IP_LIMIT = 3000
# A reservation counts toward the pending cap while its upload is alive: begun
# or given a part in the last 20 minutes (a part is 8 MB). One left behind by an
# interrupted upload stops holding a place long before its hour (DTF-WEB-14).
PENDING_IDLE_MINUTES = 20
def upload_ip_limit(request: Request):
@@ -44,9 +48,10 @@ def begin_upload(body: UploadStart, session_id=Depends(owner), _source=Depends(u
c.execute('SELECT pg_advisory_xact_lock(804208)')
usage = c.execute('''SELECT COALESCE(sum(size),0) AS total,
COALESCE(sum(size) FILTER(WHERE owner=%s),0) AS owned,
count(*) FILTER(WHERE owner=%s AND NOT complete) AS pending
count(*) FILTER(WHERE owner=%s AND NOT complete
AND expires_at > now() + interval '1 hour' - make_interval(mins => %s)) AS pending
FROM dtf_local.uploads WHERE purged_at IS NULL''',
(session_id,session_id)).fetchone()
(session_id,session_id,PENDING_IDLE_MINUTES)).fetchone()
storage_full = (usage['total']+body.size > int(os.environ.get('STORAGE_QUOTA_BYTES','53687091200')) or
usage['owned']+body.size > int(os.environ.get('OWNER_UPLOAD_QUOTA_BYTES','10737418240')))
pending_full = usage['pending'] >= int(os.environ.get('MAX_PENDING_UPLOADS','30'))