Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Android: `HttpClient$FutureShim` JNI references are never released after requests complete, leading to a reference-table overflow abort

未关闭
#1,551 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
1-2 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
android, cpp
领域
backend, mobile

调研方向

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
  1. Run an app that sends 1DS telemetry over the default Android HttpClient.
  2. Force a GC, capture a heap dump, and count HttpClient$FutureShim instances.
  3. Generate normal activity and let queued uploads finish.
  4. 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, and callable, runner and waiters are all null.
  • Representative instances are held directly by ROOT_JNI_LOCAL roots.
  • Crash evidence from the field shows about 50,257 FutureShim references 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 calls DeleteLocalRef on it. These calls run on native threads that are attached and never detached, so local references are never freed automatically. That matches the ROOT_JNI_LOCAL roots we see.
  • The global reference: m_java_request = env->NewGlobalRef(result) is released only in ~HttpRequest(). Any path that removes the request from m_requests without destroying the HttpRequest would keep the global reference alive. Those paths are dispatchCallback → GetAndRemoveRequest, CallbackForCancel and CancelAllRequests.
  • Minor: CallbackForCancel leaks the local reference returned by GetObjectClass.
Suggested fix
  • Call DeleteLocalRef(result) after executeTask and on the cancel path.
  • Release m_java_request with DeleteGlobalRef as soon as the request reaches a final state (success, cancel, retry replacement, or error/early return), rather than relying on the HttpRequest destructor.
  • Optionally wrap request sends in PushLocalFrame/PopLocalFrame on 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/cpp_client_telemetry 的其他 Issue

查看 microsoft/cpp_client_telemetry 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。