Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

SentryOkHttpEventListener breaks EventListener.Factory contract

已關閉
#5,967 2 則留言 1 個 reaction 已指派 1 人 在 GitHub 檢視

@markushi 已經在處理了。

開始於 2026年8月26日。

評估

這個 Issue 還沒有評估資料。

描述

Bug Java Platform: Java
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:

  1. use SentryOkHttpEventListener around a custom EventListener.Factory (only 1 eventListener or 1 eventListenerFactory can be set on an OkHttpClient at the same time)
  2. in the custom EventListener.Factory, capture the original Call
  3. 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

主要語言
Kotlin
星號
1.4k
分支
478
平均合併
2 天 20 小時
30 天內合併 PR
71

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

getsentry/sentry-java 的其他 Issue

查看 getsentry/sentry-java 的全部 Issue

相似的 Issue

更多 Kotlin Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。