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

Main application hangs if it initializes a KafkaProducer with sentry-java 6.19.1 #2744

Closed
tjerkw opened this issue May 29, 2023 · 5 comments · Fixed by #2747
Closed

Main application hangs if it initializes a KafkaProducer with sentry-java 6.19.1 #2744

tjerkw opened this issue May 29, 2023 · 5 comments · Fixed by #2747
Assignees
Labels
Platform: Java Type: Bug Something isn't working

Comments

@tjerkw
Copy link

tjerkw commented May 29, 2023

Integration

sentry

Java Version

eclipse-temurin:11-jre

Version

6.19.1 upwards

Steps to Reproduce

Build this file with sentry-sdk 6.19.1:

import org.apache.kafka.clients.producer.KafkaProducer

class ReproduceSentryIssue {
    private val kafkaProducer: KafkaProducer<String, String> =
        KafkaProducer(...)

    companion object {

        @JvmStatic
        fun main(args: Array<String>) {
             ReproduceSentryIssue()
        }
    }
}

Run it with a logback appender:

    <!-- Configure the Sentry appender, overriding the logging threshold to the WARN level -->
    <appender name="Sentry" class="io.sentry.logback.SentryAppender">
        <!-- Optionally change minimum Event level. Default for Events is ERROR -->
        <minimumEventLevel>WARN</minimumEventLevel>
        <!-- Optionally change minimum Breadcrumbs level. Default for Breadcrumbs is INFO -->
        <minimumBreadcrumbLevel>INFO</minimumBreadcrumbLevel>
    </appender>

Run it on docker image FROM eclipse-temurin:11-jre

Result:

  • Main application never exists, it never returns.

Workaround: Downgrade to 6.18.1

Note: Also reproducable with 6.20.1

Expected Result

The application should cleanly exit

Actual Result

It hangs, only stops with CTRL-C

@tjerkw tjerkw added Platform: Java Type: Bug Something isn't working labels May 29, 2023
@adinauer
Copy link
Member

Hello @tjerkw I'm able to reproduce. Will investigate.

I've modified our Logback sample. See https://github.com/getsentry/sentry-java/compare/feat/kafka-logback-repro for what I tried.

I combined this with a kafka server:

cat docker-compose.yml
version: "2"

services:
  kafka:
    image: docker.io/bitnami/kafka:3.4
    ports:
      - "9092:9092"
    volumes:
      - "kafka_data:/bitnami"
    environment:
      - ALLOW_PLAINTEXT_LISTENER=yes

volumes:
  kafka_data:
    driver: local

@adinauer
Copy link
Member

Seems to be coming from our new ANR detection #2697

More specifically these method invocations:

notifyOptionsObservers(options);
finalizePreviousSession(options, HubAdapter.getInstance());

Also this doesn't seem to be linked to Kafka. It's also happening in our Logback sample.

@tjerkw can you please try explicitly calling Sentry.close().

@adinauer adinauer self-assigned this May 30, 2023
@adinauer
Copy link
Member

adinauer commented May 30, 2023

These invocations should be fine but we're now replacing the ExecutorService. We shouldn't do that for NoOpSentryExecutorService. See

// If the executorService passed in the init is the same that was previously closed, we have to
// set a new one
final ISentryExecutorService sentryExecutorService = options.getExecutorService();
// If the passed executor service was previously called we set a new one
if (sentryExecutorService.isClosed()) {
options.setExecutorService(new SentryExecutorService());
}

@adinauer
Copy link
Member

@tjerkw we've opened #2747 to fix this by using daemon threads that no longer block shutdown.

@tjerkw
Copy link
Author

tjerkw commented May 30, 2023 via email

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
None yet
Development

Successfully merging a pull request may close this issue.

2 participants