Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix Space temp object cleanup race

Anand Baburajan1562e63d221f
diff --git a/server/space/repo/temp_objects.go b/server/space/repo/temp_objects.go
index cecf184b66..bc051847b1 100644
--- a/server/space/repo/temp_objects.go
+++ b/server/space/repo/temp_objects.go
@@ -60,7 +60,8 @@ func (r *AssetsRepository) GetTempObject(ctx context.Context, objectKey, purpose
func ConsumeTempObjectTx(ctx context.Context, tx *sql.Tx, objectKey, purpose string, spaceID *string) error {
args := []any{objectKey, purpose}
- query := `DELETE FROM space_temp_objects WHERE object_key = $1 AND purpose = $2`
+ // Cleanup changes cleanup_after before deleting from S3, claiming the object.
+ query := `DELETE FROM space_temp_objects WHERE object_key = $1 AND purpose = $2 AND cleanup_after = expires_at`
if spaceID != nil {
args = append(args, *spaceID)
query += fmt.Sprintf(" AND space_id = $%d", len(args))