Skip to content

DirectoryProcessor: InterruptedException caught but interrupt flag never restored — thread pool shutdown silently broken #5849

Description

@tsushanth

Bug

In sentry/src/main/java/io/sentry/DirectoryProcessor.java (around lines 94–96), a Thread.sleep(ENVELOPE_PROCESSING_DELAY) inside the processing loop is wrapped by an outer try { } catch (Throwable e) block. The catch block logs the error and returns — but never restores the thread's interrupt flag:

} catch (Throwable e) {
    logger.log(SentryLevel.ERROR, "Failed to process envelope.", e);
    return; // interrupt flag silently consumed
}

The inline comment even says "InterruptedException will be handled by the outer try-catch" — but that handler only discards the exception without calling Thread.currentThread().interrupt().

Any executor thread (e.g. ScheduledThreadPoolExecutor) running processDirectory() that receives an interrupt will silently consume it. The executor never sees the interrupt propagate, preventing clean shutdown for thread pools that rely on interrupt-based termination.

Fix

Restore the interrupt flag in the catch block:

} catch (Throwable e) {
    if (e instanceof InterruptedException) {
        Thread.currentThread().interrupt();
    }
    logger.log(SentryLevel.ERROR, "Failed to process envelope.", e);
    return;
}

Impact

  • SDK shutdown that relies on interrupting the DirectoryProcessor executor thread may hang indefinitely
  • Thread pool shutdown (awaitTermination) can block past its timeout
  • The issue is silent — no log indicates the interrupt was swallowed

Metadata

Metadata

Assignees

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions