Garbage: retry the apply after the deleting transaction has committed
Test and deploy / test (push) Successful in 55s
Test and deploy / deploy (push) Successful in 1m19s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daan MeijerandClaude Opus 5.5 committed 2026-10-08 11:50:46 +02:00
1 parent 3a60a0aa2c
commit 36f84ae3e6
1 file changed
+15 -11
+15 -11
View File
@@ -158,19 +158,23 @@ class ContentService {
* what it found. Then the release is deleted if it turned out to be garbage (D42).
*/
async apply(task: InspectTask, probe: InspectProbe): Promise<ContentResult> {
let result: ContentResult
try {
result = await this.applyProbe(task, probe)
} catch (error: any) {
// Another probe deleted a release this one writes to as garbage meanwhile (LOG.md 2026-10-08 (7)):
// the file's own release (nothing left to do), or one its par2 set joins (once more: the set
// then finds the release's files gone and makes its own).
if (error.code !== '23503') throw error
if (!(await db.from('files').where('id', task.fileId).select('id').first())) {
return { named: 0, contentType: probe.contentType, garbage: 'deleted meanwhile' }
let result: ContentResult | undefined
// Another probe deleted a release this one writes to as garbage meanwhile (LOG.md 2026-10-08 (7)):
// the file's own release (nothing left to do), or one its par2 set joins. Again once that
// deletion has committed: the set then finds the release's files gone and makes its own.
for (const wait of [0, 1000, 3000]) {
if (wait) await new Promise((resolve) => setTimeout(resolve, wait))
try {
result = await this.applyProbe(task, probe)
break
} catch (error: any) {
if (error.code !== '23503' || wait === 3000) throw error
if (!(await db.from('files').where('id', task.fileId).select('id').first())) {
return { named: 0, contentType: probe.contentType, garbage: 'deleted meanwhile' }
}
}
result = await this.applyProbe(task, probe)
}
if (!result) throw new Error(`Applying the probe of file ${task.fileId} gave no result`)
result.garbage = (await GarbageFilter.afterProbe(task.fileId, probe.contentType)) ?? undefined
return result
}