SentryOkHttpEventListener breaks EventListener.Factory contract
@markushi y travaille déjà.
Depuis le 26/8/2026.
Évaluation
Cette issue n'a pas encore été évaluée.
Description
Integration
sentry-okhttp
Java Version
8 but it's unrelated
Other Error Monitoring Solution
No
Other Error Monitoring Solution Name
No response
Version
8.21.1 but it's unrelated
Steps to Reproduce
This might be more related to the Sentry Android Gradle plugin than the Java project per se, but if we want to use SentryOkHttpEventListener (which I presume sends some useful Breadcrumbs? at least) I think the fix will need to be here (or for the Gradle plugin to use EventListener.plus in OkHttp 5.13, I think).
It looks like SentryOkHttpEventListener isn't designed for concurrency and that it breaks the EventListener.Factory contract.
If you use a custom EventListener.Factory with the Sentry Android Gradle plugin, the custom Factory gets wrapped by the SentryOkHttpEventListener.
However, the SentryOkHttpEventListener doesn't respect the EventListener.Factory contract, which expects that the EventListener instance is used for the lifetime of the Call. Instead, SentryOkHttpEventListener will pass the latest EventListener instance to every concurrent Call, because it's updating the 1 instance it uses after every SentryOkHttpEventListener.callStart.
The steps to repro were simply:
- use SentryOkHttpEventListener around a custom EventListener.Factory (only 1 eventListener or 1 eventListenerFactory can be set on an OkHttpClient at the same time)
- in the custom EventListener.Factory, capture the original Call
- launch multiple overlapping requests
private class MismatchDetectingListener(
private val ownCall: Call,
private val mismatches: MutableList<String>,
) : EventListener() {
private fun verify(method: String, cbCall: Call) {
if (cbCall !== ownCall) {
val msg = "MISMATCH $method: built for ${ownCall.request().url} invoked with ${cbCall.request().url} " +
"thread=${Thread.currentThread().name}"
mismatches += msg
Log.e(TAG, msg)
}
}
override fun callStart(call: Call) = verify("callStart", call)
override fun dnsStart(call: Call, domainName: String) = verify("dnsStart", call)
}
....
val perCallFactory = EventListener.Factory { call -> MismatchDetectingListener(call, mismatches) }
val client = OkHttpClient.Builder()
.eventListener(SentryOkHttpEventListener(originalEventListenerFactory = perCallFactory))
.build()
....
val response1 = async { client.newCall(request1).execute() }
val response2 = async { client.newCall(request2).execute() }
val response3 = async { client.newCall(request3).execute() }
val response4= async { client.newCall(request4).execute() }
Expected Result
Each EventListener should only ever receive calls from the Call it was created alongside in EventListener.Factory.create
Actual Result
The latest EventListener that was created receives every callback
- Langage dominant
- Kotlin
- Étoiles
- 1.4k
- Forks
- 478
- Merge moyen
- 2 j 20 h
- PR mergées (30 j)
- 71
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de getsentry/sentry-java
-
Improvement Java Platform: Android Platform: Java
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
getsentry/sentry-java#6145 · 1 commentaire · 1 personne assignée ·
-
Bug Java Platform: Android Platform: Java
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
getsentry/sentry-java#6138 · 1 commentaire ·
-
Feature Java Platform: Java Spans
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
getsentry/sentry-java#5984 · 1 commentaire ·
-
Android Task Traces
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
getsentry/sentry-java#5376 · 1 commentaire ·
-
Android Docs Errors
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
getsentry/sentry-java#5375 · 1 commentaire ·
Toutes les issues de getsentry/sentry-java
Issues similaires
-
[Bug] 统计页面无法重置token和汇率 Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
AAswordman/Operit#1265 · 3 commentaires ·
-
Tambahkan bahasa Indonesia Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
acristescu/OnlineGo#216 ·
-
Remove custom segment colors Ouverteenhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
libre-tube/LibreTube#8803 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
status: waiting-for-triage type: bug
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
spring-projects/spring-security#19781 ·