Skip to content

Commit fbe4e54

Browse files
committed
fix: self-healing should only trigger on ENOENT, not all fs errors
fs.access() throws for permission errors, NFS timeouts, and other transient I/O failures — not just missing files. The catch-all was incorrectly deleting DB records for files that exist but are temporarily inaccessible. Now only ENOENT triggers cleanup.
1 parent f2fc76b commit fbe4e54

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

server/lib/placeholders/services/PlaceholderCleanup.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -788,31 +788,39 @@ export async function cleanupPlaceholdersForConfig(
788788
);
789789
try {
790790
await fs.access(fullPath);
791-
} catch {
792-
// File missing — clear DB record to unblock recreation
793-
logger.info(
794-
'Placeholder file missing for active item — removing DB record for re-creation',
795-
{
796-
label: 'PlaceholderService',
797-
title: placeholder.title,
798-
tmdbId: placeholder.tmdbId,
799-
path: fullPath,
791+
} catch (fileError) {
792+
// Only treat ENOENT (file not found) as genuinely missing.
793+
// Permission errors, NFS timeouts, etc. should not trigger cleanup.
794+
const isFileNotFound =
795+
fileError instanceof Error &&
796+
'code' in fileError &&
797+
(fileError as NodeJS.ErrnoException).code === 'ENOENT';
798+
799+
if (isFileNotFound) {
800+
logger.info(
801+
'Placeholder file missing for active item — removing DB record for re-creation',
802+
{
803+
label: 'PlaceholderService',
804+
title: placeholder.title,
805+
tmdbId: placeholder.tmdbId,
806+
path: fullPath,
807+
}
808+
);
809+
810+
if (
811+
placeholder.mediaType === 'tv' &&
812+
placeholder.plexRatingKey
813+
) {
814+
await deletePlexPlaceholderEpisode(
815+
plexClient,
816+
placeholder.plexRatingKey,
817+
placeholder.title
818+
);
800819
}
801-
);
802820

803-
if (
804-
placeholder.mediaType === 'tv' &&
805-
placeholder.plexRatingKey
806-
) {
807-
await deletePlexPlaceholderEpisode(
808-
plexClient,
809-
placeholder.plexRatingKey,
810-
placeholder.title
811-
);
821+
await repository.remove(placeholder);
822+
removedCount++;
812823
}
813-
814-
await repository.remove(placeholder);
815-
removedCount++;
816824
}
817825
}
818826
}

0 commit comments

Comments
 (0)