Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary Blocking in UncaughtExceptionHandlerIntegration When RateLimiter Is Active #3857

Open
kkrawczy opened this issue Nov 7, 2024 · 1 comment
Labels
Platform: Java Type: Bug Something isn't working

Comments

@kkrawczy
Copy link

kkrawczy commented Nov 7, 2024

Integration

sentry

Java Version

19

Version

7.16.0

Steps to Reproduce

  1. Configure your DSN with a low limit, 1.
  2. Run a script that triggers many uncaughtException and observe how slow the handling gets. This line in the console can confirm slowdown: Timed out waiting to flush event to disk before crashing. Event: %s
    Simple script:
public class SentryTest {
    public static void main(String[] args) throws InterruptedException {
        Sentry.init(options -> {
            options.setDsn("XYZ");
            options.setEnvironment("XYZ");
            options.setDebug(true);
        });
        for(int i = 0; i < 100; i++) {
            System.out.println("Iteration: " + i);
            Thread workerThread = new Thread(() -> {
                Thread thread = Thread.currentThread();
                thread.getUncaughtExceptionHandler().uncaughtException(thread, new Exception("This is a test exception"));
            });

            long startTime = System.nanoTime();
            workerThread.start();
            workerThread.join();

            long durationInMillis = (System.nanoTime() - startTime) / 1_000_000;

            if (durationInMillis > 1000) {
                throw new IllegalStateException("Sentry blocked the thread");
            }
        }
    }
}

Expected Result

Don't block the thread, which could potentially slow down different parts of the user app.

Most probably, the latch used by BlockingFlushHint should be properly released in RateLimiter like you already do for other hints (markHintWhenSendingFailed)

Actual Result

The thread blocks for 15 seconds, blocking other parts of the user application.

The workaround could be to reduce flushTimeoutMillis.

@kkrawczy kkrawczy added Platform: Java Type: Bug Something isn't working labels Nov 7, 2024
@kkrawczy kkrawczy changed the title UncaughtExceptionHandlerIntegration blocks unnecessirly when RateLimiter kicks in Unnecessary Blocking in UncaughtExceptionHandlerIntegration When RateLimiter Is Active Nov 7, 2024
@adinauer
Copy link
Member

Thanks for opening this issue @kkrawczy, we'll look into it and update here once we did, can't say when we'll get to it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Java Type: Bug Something isn't working
Projects
Status: No status
Status: Needs Discussion
Development

No branches or pull requests

2 participants