[Crashlytics] OutOfMemoryError in OkHttp logging/interceptors and heap pressure — 31 events, still occurring on 2.13.0

XMLWordPrintable

    • FLW Sprint 56
    • FLW Mobile App
    • Prod

      Summary

      OutOfMemoryError crashes in OkHttp interceptor, logging, framework, view-inflation and Room frames; the 2.13.0 body-capped logging interceptor still OOMs.

      Background / Context

      Source: Sakhi/Niramay Crashlytics RCA (Oct 12 – Nov 10 2026, latest release 2.13.0 (70)). RCA ref RCA-02, status: Root Cause Not Conclusively Established (no heap dump, no stack trace opened, response sizes not measured). Code inspected: PSMRI/FLW-Mobile-App, main, commit f90f07c3. Priority: P1. 31 events across 12 issues (18 open, 13 closed ApiAnalyticsInterceptor).

      Problem Statement

      Allocations fail when large bodies are buffered, and elsewhere the heap is already near its limit.

      Current Behaviour (Actual)

      Crashlytics issues (events / users):

      • ApiAnalyticsInterceptor.intercept (:26, closed) — 13 / 2 — 2.8.6 → 2.12.1, repetitive
      • BodyCappedLoggingInterceptor.intercept (:31) — 4 / 4 — new in 2.13.0
      • AccountDeactivationInterceptor.intercept (:15) — 4 / 2 — 2.8.1 → 2.13.0
      • ThreadLocalWorkSource.setUid — 2 / 1; DataBinderMapperImpl, BenDao_Impl$58, BenDao_Impl.__fetchRelationship…, AssistStructure, ShapePath, PreferenceDao.getLoggedInUser, AlertNewBenBinding.inflate, SyncLogManager$scheduleEmit (1 / 1 each, 2.8.1 → 2.12.1)

      Code findings (current main):

      • BodyCappedLoggingInterceptor caps only the REQUEST body (1 MB). Requests under the cap and every response are logged at Level.BODY, which buffers the whole body into a String before LoggingInterceptor truncates the log line to 4 KB.
      • AccountDeactivationInterceptor does peekBody(1 MB).string() and a JSONObject parse on every response.
      • AppModule comment: BODY logging "feeds the sync log in release too". largeHeap=true hides growth.
      • Retained OkHttp log memory is small (4 KB x 500 entries), so transient copies, not the retained buffer, are the likely pressure. SyncLogTree has no size cap and does message.lowercase() on non-OkHttp messages; SyncLogManager copies the 500-entry buffer every 250 ms; BenDao relation queries load full result sets.

      Expected Behaviour / Requirement

      Large uploads/downloads and normal sync must not exhaust the heap; logging must not copy unbounded bodies.

      User Story

      As a field user syncing data on a low-memory device, I want sync to complete without the app crashing.

      Acceptance Criteria

      • Given a large response body, When sync runs, Then response logging does not buffer the whole body (HEADERS-only when length is unknown or above the limit) (CAPA-06).
      • Given any API response, When AccountDeactivationInterceptor runs, Then it reads only small JSON bodies (or only relevant endpoints) (CAPA-07).
      • Given a 20 MB log message, When it reaches SyncLogTree, Then it is truncated before any copy and heap stays flat (CAPA-08).
      • Given a full sync on a low-RAM device, When profiled, Then retained and peak heap stay bounded; profile attached to the release checklist; Crashlytics OOM alert configured (CAPA-09).
      • Given the BenDao relation queries, When run on a large dataset, Then results are paged or projected (CAPA-10).
      • No new OOM events at BodyCappedLoggingInterceptor after release.

      Business Rules / Validations

      • Whether release builds must keep BODY logging for the sync log: [TBD/CLARIFICATION REQUIRED].

      Dependencies

      None identified. Related to FLW ticket for RCA-01 (FLW-1255) only by app-startup memory conditions (unproven).

      Impact / Affected Areas

      AppModule.kt (interceptor wiring), BodyCappedLoggingInterceptor.kt, LoggingInterceptor.kt, AccountDeactivationInterceptor.kt, SyncLogTree.kt, SyncLogManager.kt, SyncLogFileWriter.kt, BenDao queries; all sync flows.

      Out of Scope

      Separate memory-leak hunt unless OOM persists after the above fixes.

      QA / Testing Considerations

      Full sync with large payloads on low-RAM device; heap profile before/after; confirm Crashlytics OOM count on 2.13.x/3.0.

      Open Questions / Clarifications

      • Which endpoints return large responses? Which devices OOM (open issue pages, enable heap dumps)?
      • Is BODY logging required in release builds?
      • Why does BodyCappedLoggingInterceptor.kt:31 still fail on 2.13.0?

      Source: Sakhi_Niramay_Crashlytics_RCA.xlsx (RCA-02, CAPA-06 to CAPA-10). RCA is a draft pending human confirmation.

              Assignee:
              Nikhil Ananda Fegade
              Reporter:
              Shivani Garg
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: