Bug: "Generating previews..." spinner never completes after PDF compression
Bug: "Generating previews..." spinner never completes after PDF compression
Version: 2.7.2 Deployment: Docker (self-hosted)
Describe the bug After compressing a PDF, the compression itself completes successfully (confirmed in logs), but the UI gets stuck on "Generating previews..." indefinitely. The download button never appears and the user cannot proceed.
Steps to reproduce
- Upload a PDF file (tested with a 3.53 MB file containing embedded JPEG images)
- Select compression settings and click Compress
- Compression completes successfully (visible in logs)
- UI shows "Generating previews..." spinner — never resolves
Expected behavior After compression completes, preview is generated and the download button appears.
Actual behavior UI is permanently stuck on "Generating previews...". No error is shown to the user.
Logs
Compression completes successfully at e.g. 06:42:31:
INFO CompressController - Overall PDF compression: 3.53 MB → 780.48 KB (reduced by 78.4%)
INFO CompressController - Saving compressed PDF to /tmp/stirling-pdf/stirling-pdf/stirling-pdf-14594374465729347323.pdf
Three seconds later, TempFileCleanupService runs:
INFO TempFileCleanupService - Running scheduled temporary file cleanup
INFO TempFileManager - Cleaned up 0 old temporary files
No preview-related log entries appear after compression completes.
Environment
- Docker image:
stirlingtools/stirling-pdf:2.7.2 - JVM: OpenJDK 25.0.2
STIRLING_JVM_PROFILE=balancedSECURITY_LOGINMETHOD=saml2PREMIUM_ENABLED=true- Host OS: Ubuntu, SSD storage
- Memory at time of compression: ~1.65 GiB used of 3.82 GiB available (43%)
Workaround None found. User must reload the page and re-upload the file.
Hey, I would like to solve this issue, could you please assign me? @Alingsaskommun @Frooodle @ConnorYoh
Investigation
Traced the full frontend flow from compress API response → thumbnail generation → UI state. The backend works fine (as reported). The bug is in the frontend thumbnail/worker lifecycle.
Root Cause Chain
1. PDF document leak in generatePDFThumbnail (primary)
frontend/src/core/utils/thumbnailUtils.ts ~L544-565
If generateStandardPDFThumbnail() throws any error that isn't a PasswordException, the PDF document is never destroyed — the worker stays in activeDocuments permanently:
try {
const pdf = await pdfWorkerManager.createDocument(arrayBuffer, { ... });
const thumbnail = await generateStandardPDFThumbnail(pdf, scale); // if this throws...
pdfWorkerManager.destroyDocument(pdf); // ...this is skipped
return thumbnail;
} catch (error) {
if (error instanceof Error && error.name === "PasswordException") {
return generateEncryptedPDFThumbnail(file);
}
throw error; // re-thrown WITHOUT destroying the PDF
}
The same pattern exists in generateThumbnailWithMetadata (~L695-704) — the catch returns a placeholder but never destroys the PDF.
2. Worker pool exhaustion
frontend/src/core/services/pdfWorkerManager.ts ~L143-154
After enough leaked documents, the worker pool (max 10) fills up. waitForAvailableWorker() blocks indefinitely with no timeout or fallback.
3. isGeneratingThumbnails never reset on error
frontend/src/core/hooks/tools/shared/useToolOperation.ts ~L305-310
actions.setGeneratingThumbnails(true);
const [thumbnails, downloadInfo] = await Promise.all([
generateThumbnails(processedFiles),
createDownloadInfo(processedFiles, config.operationType),
]);
actions.setGeneratingThumbnails(false); // never reached if Promise.all rejects or hangs
The finally block resets isLoading but not isGeneratingThumbnails, so the spinner stays visible forever.
Reproduction Path
- Compress a PDF (backend succeeds, returns the file)
- Frontend calls
generateThumbnails()on the result - PDF rendering throws during thumbnail generation (e.g. corrupted page, unsupported feature)
- PDF document leaks → worker pool shrinks
- On repeated use, pool fills →
waitForAvailableWorkerhangs forever Promise.allnever resolves → "Generating previews..." spinner stuck indefinitely
Suggested Fixes
try/finallyfor PDF cleanup ingeneratePDFThumbnailandgenerateThumbnailWithMetadata— ensuredestroyDocumentis always called- Reset
isGeneratingThumbnailsin thefinallyblock ofuseToolOperation, not justisLoading - Add a timeout to thumbnail generation so it can't hang indefinitely even if the worker pool is exhausted
Thanks for this research! You are welcome to raise PR for this