Android: `HttpClient$FutureShim` JNI references are never released after requests complete, leading to a reference-table overflow abort
还没有人认领这个 Issue。
评估
调研方向
Start in lib/http/HttpClient_Android.cpp and trace SendRequestAsync, dispatchCallback, CallbackForCancel, and CancelAllRequests, checking how JNI local and global references are released on completion and cancellation. Reproduce the reported reference growth with the heap dump steps in the issue, then verify completed, cancelled, and failed requests release their references.
由索引模型根据 Issue 内容生成。
描述
Summary
On Android, completed com.microsoft.applications.events.HttpClient$FutureShim objects (the FutureTask created by createTask) build up as JNI GC roots and are never released. Over a long session this approaches ART's 51,200-entry JNI reference limit and the process aborts with JNI ERROR (app bug): global reference table overflow in HttpClient_Android::SendRequestAsync.
Environment
- SDK: maesdk
3.10.40.1(a Teams-specific build based on this repo) - Device: Samsung SM-A146B, Android 15 (API 35)
Repro
- Run an app that sends 1DS telemetry over the default Android
HttpClient. - Force a GC, capture a heap dump, and count
HttpClient$FutureShiminstances. - Generate normal activity and let queued uploads finish.
- Force a GC and capture a second heap dump. Leave the app idle for 3 minutes and capture a third.
Expected: after completion, cancellation or failure, FutureShim instances become collectable and the count falls back toward baseline.
Actual: the count only goes up across heap dumps taken after a forced GC: 2,194 → 2,587 → 2,607.
- Every inspected instance is already complete:
FutureTask.state == 2, andcallable,runnerandwaitersare all null. - Representative instances are held directly by
ROOT_JNI_LOCALroots. - Crash evidence from the field shows about 50,257
FutureShimreferences at the time of the reference-table overflow abort.
Suspected cause (lib/http/HttpClient_Android.cpp)
SendRequestAsync:result = env->PopLocalFrame(result)hands back a new local reference in the caller's frame, and nothing ever callsDeleteLocalRefon it. These calls run on native threads that are attached and never detached, so local references are never freed automatically. That matches theROOT_JNI_LOCALroots we see.- The global reference:
m_java_request = env->NewGlobalRef(result)is released only in~HttpRequest(). Any path that removes the request fromm_requestswithout destroying theHttpRequestwould keep the global reference alive. Those paths aredispatchCallback→GetAndRemoveRequest,CallbackForCancelandCancelAllRequests. - Minor:
CallbackForCancelleaks the local reference returned byGetObjectClass.
Suggested fix
- Call
DeleteLocalRef(result)afterexecuteTaskand on the cancel path. - Release
m_java_requestwithDeleteGlobalRefas soon as the request reaches a final state (success, cancel, retry replacement, or error/early return), rather than relying on theHttpRequestdestructor. - Optionally wrap request sends in
PushLocalFrame/PopLocalFrameon persistently attached threads.
Workaround
None on the app side. The leaked references are owned by the SDK, and an app cannot safely release them.
- 主要语言
- C
- 星标
- 104
- 派生
- 67
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 8
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/cpp_client_telemetry 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
microsoft/cpp_client_telemetry#1550 ·
-
C API enhancement
难度 2/5 1-3 小时 新手友好度 62/100
-
OneDS C++ SDK retries already-ingested iOS events, causing duplicate telemetry records可能已有人在做 @bmehta001 于 25 天前认领。 未关闭bug
难度 5/5 一周以上 新手友好度 35/100
microsoft/cpp_client_telemetry#1542 · 3 条评论 · 已指派 1 人 ·
-
难度 5/5 一周以上 新手友好度 35/100
microsoft/cpp_client_telemetry#1504 ·
-
bug
难度 4/5 3-5 天 新手友好度 25/100
microsoft/cpp_client_telemetry#1413 · 2 条评论 ·
查看 microsoft/cpp_client_telemetry 的全部 Issue
相似的 Issue
-
difficulty: easy
难度 2/5 1-3 小时 新手友好度 64/100
-
难度 2/5 1-3 小时 新手友好度 65/100
-
performance solver
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
ChefKissInc/Inferno#319 ·
-
llvm-tools
难度 1/5 1 小时以内 新手友好度 72/100
llvm/llvm-project#235522 ·
维护者通常 1 天内回复