Skip to content

ANR: getEnvironmentInformation() blocks main thread during start() — needs a FeatureFlag to disable memory sampling #489

Description

@bat-writes-code

NewRelic.start() must be called on the main thread per docs, but internally AndroidAgentImpl.initialize() → AnalyticsControllerImpl.reinitialize() → getEnvironmentInformation()
blocks the main thread by calling Future.get(100, MILLISECONDS) on a Sampler.sampleMemory() task that does ActivityManager.getProcessMemoryInfo() (Binder IPC).

While v7.7.1 moved the Binder IPC to a background executor, the calling thread still blocks on Future.get(). On low-end devices during cold start, this contributes to ANRs.

There is no FeatureFlag to disable this. Sampler.init() is called unconditionally in AndroidAgentImpl.initialize() with no feature gate. We checked all 18 available FeatureFlags —
none control the Sampler.

ANR trace:
at com.newrelic.agent.android.sample.Sampler.sampleMemory(Sampler.java:278)
at com.newrelic.agent.android.AndroidAgentImpl.getEnvironmentInformation(AndroidAgentImpl.java:332)
at com.newrelic.agent.android.analytics.AnalyticsControllerImpl.reinitialize(AnalyticsControllerImpl.java:187)
at com.newrelic.agent.android.analytics.AnalyticsControllerImpl.initialize(AnalyticsControllerImpl.java:112)
at com.newrelic.agent.android.AndroidAgentImpl.initialize(AndroidAgentImpl.java:203)
at com.newrelic.agent.android.AndroidAgentImpl.start(AndroidAgentImpl.java:500)
at com.newrelic.agent.android.NewRelic.start(NewRelic.java:301)

Agent version: 7.7.1

Request: Please add a FeatureFlag (e.g. FeatureFlag.MemorySampling) to allow apps to disable Sampler initialization and sampleMemory() calls during start(). Many apps only use
NewRelic for HTTP monitoring and user attributes — memory stats are not needed, and the Binder IPC during init causes ANRs on production devices that we cannot work around without
violating the "call start() on main thread" requirement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions