Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta
#1,551 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
48/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
android, cpp
Domínio
backend, mobile

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
C
Estrelas
104
Forks
67
Merge médio
2d 12h
PRs com merge (30d)
8

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de microsoft/cpp_client_telemetry

Todas as issues de microsoft/cpp_client_telemetry

Issues semelhantes

Mais issues de C

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.