From 7b88334981eae3eb9911282d504966db89852d78 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 18 Jun 2026 04:18:02 +0000 Subject: [PATCH] fix(storage): return 404 instead of 500 on concurrent file deletion When two requests delete the same file concurrently, both pass the existence check and remove the device file. The first request's deleteDocument() succeeds; the second sees the document already gone (Database::deleteDocument() returns false when the document is empty) and threw GENERAL_SERVER_ERROR ("Failed to remove file from DB"), surfacing a 500 for a file that no longer exists. When deleteDocument() returns false, re-check the document. If it is gone, throw STORAGE_FILE_NOT_FOUND (404), consistent with the not-found check at the start of the request. Only throw the server error when the document genuinely still exists (real DB failure). --- .../Platform/Modules/Storage/Http/Buckets/Files/Delete.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php index c16b374c78..51a175b4c0 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php @@ -145,7 +145,11 @@ class Delete extends Action } if (!$deleted) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove file from DB'); + $exists = $authorization->skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); + if (!$exists->isEmpty()) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove file from DB'); + } + throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); } } else { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to delete file from device');