Closed Bug 2082763 Opened 1 month ago Closed 19 days ago

Crash in [@ java.lang.OutOfMemoryError: at java.io.ByteArrayOutputStream.<init>(ByteArrayOutputStream.java)]

Categories

(Application Services :: General, defect)

defect

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1992618

People

(Reporter: clouseau-bot, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: crash)

Crash Data

Crash report: https://crash-stats.mozilla.org/report/index/4d3c3f51-b8b0-45c1-839d-904990261013

Top 10 frames:

0  java.io.ByteArrayOutputStream  <init>
1  mozilla.appservices.viaduct.FetchBackend  sendRequest$lambda$3  mozilla/appservices/viaduct/FetchBackend.kt
2  mozilla.appservices.viaduct.FetchBackend  sendRequest  mozilla/appservices/viaduct/FetchBackend.kt
3  mozilla.appservices.viaduct.uniffiCallbackInterfaceBackend$sendRequest$callback$makeCall$1  invokeSuspend  toolkit/components/uniffi-bindgen-gecko-js/android/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/viaduct.kt
4  mozilla.appservices.viaduct.uniffiCallbackInterfaceBackend$sendRequest$callback$makeCall$1  invoke  toolkit/components/uniffi-bindgen-gecko-js/android/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/viaduct.kt
5  mozilla.appservices.viaduct.uniffiCallbackInterfaceBackend$sendRequest$callback$makeCall$1  invoke  toolkit/components/uniffi-bindgen-gecko-js/android/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/viaduct.kt
6  mozilla.appservices.viaduct.uniffiCallbackInterfaceBackend$sendRequest$callback$$inlined$uniffiTraitInterfaceCallAsyncWithError$  invokeSuspend  toolkit/components/uniffi-bindgen-gecko-js/android/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/viaduct.kt
7  kotlin.coroutines.jvm.internal.BaseContinuationImpl  resumeWith
8  kotlinx.coroutines.DispatchedTask  run
9  kotlinx.coroutines.scheduling.CoroutineScheduler$Worker  run

Filed because this signature's crash volume spiked. 35 reports from 3 distinct installations on the nightly build of 2026-10-12 (buildid 20261012185752); the preceding 3 build-days had 0, 3, 3 reports, and the loudest of its 2 earlier builds in the 21 days before had 3. That is 11.7x the loudest of the preceding build-days and of this signature's builds over the 21 days before (Clouseau's bar is 3x, and the Poisson excess of the day against that baseline is z = 8.22, bar 3.62). This signature is not new: its first report is in build 20181001155545 (2018-10-01), 2933 days before this build.

Clouseau analysis (automated -- nothing below was checked by a human; a claim it could not ground is deliberately absent):

Fenix throws a Java OutOfMemoryError while allocating the ByteArrayOutputStream that buffers an HTTP response body. The stack points at the viaduct Android backend, where FetchBackend.sendRequest reads the whole body into memory with body.useStream { it.readBytes() } and no size limit. The nightly spike is almost entirely repeat crashes from three installations (60 of the 72 reports on or after the spiking build). The same crash also rose on release 156/157 on 2026-10-14, again mostly from one installation, and none of the 56 changesets in the spiking build's pushlog touches viaduct. The next steps are to find which request returns the oversized body (Breadcrumbs or a size log), and as a defensive fix to cap or stream the body read in FetchBackend and turn the overflow into a recoverable error.

Possible path to the crash:

Mechanism (observed): a Java OutOfMemoryError in the constructor of java.io.ByteArrayOutputStream, in the parent process; there is no native minidump thread list.

Path (inferred, medium):

  1. A viaduct request from a Rust component goes through the uniffi bindings (viaduct.kt invokeSuspend) into FetchBackend.sendRequest.
  2. FetchBackend.sendRequest sends the request with client.value.fetch(fetchReq) and then reads the whole response body into memory with fetchResp.body.useStream { it.readBytes() }, with no size limit (FetchBackend.kt:62-64).
  3. The ByteArrayOutputStream created inside that read cannot get its buffer, probably because the response is very large or available() reports a large size, and the error propagates as an uncaught OOM.
    The frames are R8-remapped and their line numbers are unreliable, and I did not read the Kotlin stdlib readBytes(), so the exact allocation size is unverified.

Trigger (inferred, low): a response body that is too large for the Java heap on a few specific installations, possibly during startup (the representative report has an uptime of 8 s). Which endpoint or component made the request is unknown.

Checked:

  • FetchBackend.sendRequest reads the full response body with fetchResp.body.useStream { it.readBytes() } and has no size limit. (third_party/application-services/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/FetchBackend.kt@98fd4e220ec9:54-64)
  • FetchBackend.kt was last changed in f0803013607f (bug 2055557, a-s update, 2026-07-16), long before the spiking build. (file_history FetchBackend.kt (nightly, pinned))
  • On nightly over the last 30 days, 72 reports are on or after build 20261012185752 and 6 are before it. Of the 72, 60 come from three install_time values (1792021072: 26, 1791856595: 20, 1791873094: 14). (facets install_time, split_at_build 20261012185752, nightly, 30d)
  • Across all channels in the last 7 days, 114 of 235 reports share one install_time (1791595109), which matches the release burst on 2026-10-14 (157.0, 157.0.1 and 156.0.1). (facets install_time all_channels 7d; facets version by_day all_channels 10d)
  • The nightly spike is split across builds 20261012185752 (35) and 20261014080135 (34), so it is not tied to the pushlog of a single build. (facets build_id, nightly, 30d)
  • The representative report is a parent-process crash with uptime 8 s on a Samsung SM-S918B running Android 36, and the minidump has no thread list. (crashstats report 4d3c3f51-b8b0-45c1-839d-904990261013)
  • No Bugzilla bug references this signature. (bugzilla signature_bugs)
  • The spike is repeated crashes on a few devices, each probably making the same oversized request again, not a broad rate regression caused by a code change. [inferred, medium confidence] (the install_time concentration above, plus the simultaneous release rise on 2026-10-14 across several versions)

Alternatives considered:

  • Changesets in the 20261012185752 pushlog as the culprit: disfavored -- none of them touch viaduct or the fetch client, and release 156/157, which contain none of them, rose on the same day.
  • Hardware fault: disfavored -- the brief reports a 0% bit-flip share and 0% Raptor Lake share for this signature, and a Java heap OOM is not a typical bit-flip symptom.
  • A new crash introduced in this build: ruled out -- the brief says the signature was first seen in build 20181001155545.

Worth checking first:

  • Which request (component or URL) returns the oversized body: read the Breadcrumbs annotation on reports from the three dominant nightly installations, or add logging of the response size or content length in FetchBackend.
  • Whether every report under this generic signature goes through FetchBackend or some come from other ByteArrayOutputStream users: proto_signature and topmost_filenames are empty, so compare JavaStackTrace across several reports.
  • Whether a server-side change around 2026-10-13/14 (for example a large Remote Settings or Suggest payload) set this off on several channels at once: check with the relevant service owners.
  • The exact allocation size: confirm whether Kotlin readBytes() sizes its initial buffer from available(), and what the GeckoView fetch body stream returns from available().

Filed automatically by Clouseau, which analyses nightly crashes with an LLM. Nothing above was written or checked by a human. Please close it as INVALID if it is wrong — that is useful feedback, not a nuisance.

This is not an independent Mozilla discovery: the crash is known here only because somebody submitted the crash report linked at the top. If this duplicates an existing report, please resolve THIS bug as the duplicate and leave the credit with the earlier reporter.

Since nightly and release are affected, beta will likely be affected too.
For more information, please visit BugBot documentation.

Product: Core → Application Services

Crash report: https://crash-stats.mozilla.org/report/index/67587265-f57c-4fb1-8a15-c09950261029

Top 7 frames:

0  java.io.ByteArrayOutputStream  <init>
1  mozilla.appservices.viaduct.FetchBackend  sendRequest$lambda$3  third_party/application-services/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/FetchBackend.kt
2  mozilla.appservices.viaduct.FetchBackend  sendRequest  third_party/application-services/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/FetchBackend.kt
3  mozilla.appservices.viaduct.uniffiCallbackInterfaceBackend$sendRequest$callback$$inlined$uniffiAsyncCallback$1  invokeSuspend  toolkit/components/uniffi-bindgen-gecko-js/android/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/viaduct.kt
4  kotlin.coroutines.jvm.internal.BaseContinuationImpl  resumeWith
5  kotlinx.coroutines.DispatchedTask  run
6  kotlinx.coroutines.scheduling.CoroutineScheduler$Worker  run

Filed because this signature's crash volume spiked. 21 reports from 6 distinct installations on the beta build of 2026-10-28 (buildid 20261028090516); the preceding 1 build-day had 6 report, and the loudest of its 1 earlier build in the 21 days before had 6. That is 3.5x the loudest of the preceding build-days and of this signature's builds over the 21 days before (Clouseau's bar is 3x, and the Poisson excess of the day against that baseline is z = 4.2, bar 3.62). This signature is not new: its first report is in build 20181001155545 (2018-10-01), 2949 days before this build.

Clouseau analysis (automated -- nothing below was checked by a human; a claim it could not ground is deliberately absent):

In Fenix the viaduct Android backend (FetchBackend.sendRequest) now allocates its response buffer as ByteArrayOutputStream(Content-Length). That is one allocation of whatever size the server declares, before any body bytes are read, with no upper cap. A large or wrong Content-Length (for example on a HEAD response) can therefore exhaust the Java heap on a coroutine worker in the parent process, which is the crashing statement. The pre-sizing arrived with application-services vendoring c12d48e17397 (bug 2080808), which replaced it.readBytes(). It reached beta with the 160 merge: beta's first report is in 160.0b1, and the 160.0b2 spike is more users on that version rather than a new rate step. Recommended fix: cap the initial buffer size (or go back to the growing read), skip pre-sizing for bodyless responses, and add a viaduct-wide maximum body size.

Starting point -- a candidate, NOT an established cause (medium confidence): c12d48e17397 (bug 2080808) by :joschmidt.

At parent 0a7acd225694, FetchBackend.kt:62-64 read the body with it.readBytes(). At the crash build dbf330c544f1, FetchBackend.kt:74-79 sizes ByteArrayOutputStream(initialBufferSize) from fetchResp.headers[CONTENT_LENGTH], and coerceIn(0, Int.MAX_VALUE) is the only limit. file_history shows c12d48e17397 as the only change to this file since July. The crash frame (ByteArrayOutputStream.<init> under FetchBackend.sendRequest) is exactly this new allocation. Confidence is medium, not high: the signature already existed on release without this code, so the change explains this cohort but not the whole signature, and no report recording the failed allocation size was examined.

Possible path to the crash:

Mechanism (observed): java.lang.OutOfMemoryError thrown in java.io.ByteArrayOutputStream.<init>, called from FetchBackend.sendRequest, on a kotlinx.coroutines scheduler worker in the parent process.

Path (observed in source, ordering inferred, medium):

  1. A Rust component makes a viaduct request, which is forwarded to the Kotlin FetchBackend through the UniFFI async callback (uniffiCallbackInterfaceBackend$sendRequest).
  2. client.value.fetch(fetchReq) returns a response whose headers include Content-Length.
  3. fetchResp.body.useStream parses that header to an Int and passes it straight to ByteArrayOutputStream(initialBufferSize), with no upper bound.
  4. When the declared length is too large for the remaining Java heap (inferred), the constructor's single byte[] allocation throws OOM before any bytes are copied.

Trigger (unknown): which request or server sends a large Content-Length is not recorded in the data examined. A HEAD response, or a Content-Length larger than the bytes actually sent, would allocate the full size for an empty or small body. A truly large body would have been at risk under the old readBytes() as well, but that path grows its buffer in steps and would OOM with a different signature.

Checked:

  • At the crash build, FetchBackend.sendRequest sizes ByteArrayOutputStream from the Content-Length header, limited only by coerceIn(0, Int.MAX_VALUE); a code comment says it trusts the server not to send an oversized value. (third_party/application-services/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/FetchBackend.kt@dbf330c544f1:66-82)
  • Before c12d48e17397, the body was read with it.readBytes() and nothing was pre-sized. (FetchBackend.kt@0a7acd225694:62-64)
  • c12d48e17397 (bug 2080808, vendoring application-services f22774fb, 2026-10-13) modifies FetchBackend.kt, and it is the only change to the file since f0803013607f (2026-07-16). (mcp__history__changeset c12d48e17397; mcp__history__file_history FetchBackend.kt)
  • The representative crash stack is ByteArrayOutputStream.<init> <- FetchBackend.sendRequest$lambda$3 <- FetchBackend.sendRequest <- the UniFFI async callback <- the coroutine worker, in the parent process on Android arm64. (brief, report 67587265-f57c-4fb1-8a15-c09950261029)
  • On beta, the signature appears only on 160 builds: 20261026160927 (6), 20261028090516 (25) and 20261030090331 (9), over 30 days. (facets build_id, beta, 30d)
  • 160.0b2 is at 90.58 reports per 1000 against 33.71 for 160.0b1, which the brief says is within 3x, so there is no rate step between betas. (brief crash-rate-by-version table)
  • Nightly reports rise from 2026-10-13 (15) and 2026-10-14 (24), right after the 2026-10-13 landing, and 160.0a1 is the largest version cohort (231 of 696 in 30 days). (brief per-day table; facets version, all channels, 30d)
  • Release versions 156-159, which do not contain this code, also produce this signature (for example 157.0.1: 135 and 157.0: 105 in 30 days), so the signature covers other callers as well as this cohort. [inferred, medium confidence] (facets version, all channels, 30d; file_history shows the pre-sizing arrived 2026-10-13)

Alternatives considered:

  • Changesets in the 20261028090516 pushlog window (l10n bumps, editor/DOM/devtools uplifts): disfavored -- none touches viaduct or Android networking, and the crash was already on beta in 160.0b1 (20261026160927) before that window.
  • Failing hardware: disfavored -- 0% bit-flip and 0% Raptor Lake share on this channel, and the crash is a Java heap OOM on Android arm64.
  • A real rate increase between 160.0b1 and 160.0b2: not supported -- the per-version shares differ by less than 3x; the spike reflects 160.0b2 adoption.
  • c12d48e17397 as the cause of the release-channel reports: ruled out for release 156-159 -- those builds predate the 2026-10-13 change, so their reports must come from other ByteArrayOutputStream callers.

Worth checking first:

  • Which viaduct consumer and endpoint returns the large Content-Length: logging the request URL host and method, or a breadcrumb in FetchBackend.sendRequest when Content-Length is above a few MB, would settle it.
  • Whether the declared length is false (for example on HEAD or 204/304 responses) or the body is truly large: the fix should cap the pre-size (say at 1 MiB, or min(Content-Length, cap)), skip pre-sizing when the method is HEAD, and add a viaduct-wide maximum body size.
  • The release and older-version reports under this signature: fetch one release 157 report to confirm it has a different caller, so that cohort is triaged separately from this one.

:joschmidt, can you have a look please?

Posted automatically by Clouseau, which analyses beta and Developer Edition crashes with an LLM. Nothing above was written or checked by a human.

Flags: needinfo?(joschmidt)

:skhamis, could this be triaged and prioritized? (tagging as triage owner)
There is little time to investigate this for Fx160 as the RC builds this week.

Flags: needinfo?(skhamis)

The FetchBackend.kt change didn't come from bug 2080808 itself. That patch only vendored application-services, and this commit came along with it: https://github.com/mozilla/application-services/commit/d4057dd5972a7c83aa279f4f342d42f4b163222c (bug 2079421).

Ben, could you take a look?

Flags: needinfo?(joschmidt) → needinfo?(bdeankawamura)

Signature change for Bug 1992618

Flags: needinfo?(skhamis)

Crash report: https://crash-stats.mozilla.org/report/index/b0803d8c-fd21-435b-ad04-3e8ea0261104

Top 7 frames:

0  java.io.ByteArrayOutputStream  <init>
1  mozilla.appservices.viaduct.FetchBackend  sendRequest$lambda$3  third_party/application-services/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/FetchBackend.kt
2  mozilla.appservices.viaduct.FetchBackend  sendRequest  third_party/application-services/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/FetchBackend.kt
3  mozilla.appservices.viaduct.uniffiCallbackInterfaceBackend$sendRequest$callback$$inlined$uniffiAsyncCallback$1  invokeSuspend  toolkit/components/uniffi-bindgen-gecko-js/android/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/viaduct.kt
4  kotlin.coroutines.jvm.internal.BaseContinuationImpl  resumeWith
5  kotlinx.coroutines.DispatchedTask  run
6  kotlinx.coroutines.scheduling.CoroutineScheduler$Worker  run

Filed because this signature's crash volume spiked. 412 reports from 23 distinct installations on the release build of 2026-11-02 (buildid 20261102144711); the preceding 1 build-day had 35 report, and the loudest of its 5 earlier builds in the 42 days before had 137. That is 3.0x the loudest of the preceding build-days and of this signature's builds over the 42 days before (Clouseau's bar is 3x, and the Poisson excess of the day against that baseline is z = 17.17, bar 3.62). By version, 159.0.1 runs at 627.9x the share of 159.0 from its first days. This signature is not new: its first report is in build 20181001155545 (2018-10-01), 2954 days before this build.

Clouseau analysis (automated -- nothing below was checked by a human; a claim it could not ground is deliberately absent):

Fenix 159.0.1 runs out of Java heap when the viaduct HTTP backend (mozilla.appservices.viaduct.FetchBackend.sendRequest) creates the ByteArrayOutputStream that holds a response body. The jump to 270 per 1000 crash reports (from 0.43 in 159.0) shipped with the build. Its only plausibly related change is the Application Services bump to 159.0.2 (614eb0958982, bug 2079421 "Pre-allocate viaduct buffer"). The mozilla-central version of that code sizes the buffer from the response's Content-Length header and only clamps it to 0..Int.MAX_VALUE. So a single large response, or a large advertised length, is now allocated in one piece up front instead of growing as bytes arrive. The new crashes are concentrated in the first minute after launch (89% vs 17% before), which fits a large startup fetch that now crashes every launch. Recommended action: cap the pre-allocation, e.g. min(contentLength, a few hundred KB) with normal growth after that, or revert that part of the change in an Application Services point release and bump Fenix release to it.

Suspected regressor (medium confidence): 614eb0958982 (bug 2079421) by :bdk.

The diff only changes VERSION in ApplicationServices.kt from 159.0.1 to 159.0.2, so the shipped viaduct code comes from the AS artifact, not the in-tree copy. The bump's bug is titled "Pre-allocate viaduct buffer". The mozilla-central FetchBackend.kt (indexed tip) builds ByteArrayOutputStream(initialBufferSize) with initialBufferSize from fetchResp.headers[CONTENT_LENGTH]?.toIntOrNull()?.coerceIn(0, Int.MAX_VALUE). That is a single allocation of the full advertised size, made in the frame that crashes. I did not read the 159.0.2 artifact's source directly. The in-tree release copy at 7b34a03a910d still uses it.readBytes(), so it does not show what shipped.

Possible path to the crash:

Mechanism (observed): a java.lang.OutOfMemoryError is thrown inside java.io.ByteArrayOutputStream.<init>, called directly from FetchBackend.sendRequest$lambda$3, the body-reading lambda inside fetchResp.body.useStream { ... }, on a coroutine worker in the parent process.

Path (inferred, medium):

  1. A viaduct request from Rust components (Application Services) goes through the uniffi callback to FetchBackend.sendRequest, which calls client.value.fetch(fetchReq).
  2. In AS 159.0.2 (bug 2079421), the body lambda probably pre-sizes the buffer from the Content-Length response header, clamped only to 0..Int.MAX_VALUE.
  3. ByteArrayOutputStream(n) allocates the full array at once, and on a memory-limited heap that throws OOM before any byte is read.

Trigger (inferred, low): a viaduct fetch made early in startup whose response is, or claims to be, large; 89% of the new crashes happen with uptime under 60 s. I could not identify the endpoint. Before the bump, the same signature already occurred at a low rate through Kotlin's readBytes() buffer creation, so the signature is longstanding; what is new is the rate.

Checked:

  • Changeset 614eb0958982 only changes VERSION from "159.0.1" to "159.0.2" in mobile/android/android-components/plugins/dependencies/src/main/java/ApplicationServices.kt. (mcp__patch__diff 614eb0958982)
  • Bug 2079421, the bump's bug, is titled "Pre-allocate viaduct buffer", Application Services :: General, RESOLVED FIXED. (bug 2079421)
  • The mozilla-central FetchBackend.kt sizes ByteArrayOutputStream(initialBufferSize) from fetchResp.headers[CONTENT_LENGTH]?.toIntOrNull()?.coerceIn(0, Int.MAX_VALUE), at lines 74-79. (searchfox mozilla-central third_party/application-services/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/FetchBackend.kt#74-79 (indexed tip))
  • The in-tree release copy at the build revision still reads the body with it.readBytes() and has no pre-sizing, so it is not the code that shipped from the 159.0.2 artifact. (third_party/application-services/components/viaduct/android/src/main/java/mozilla/appservices/viaduct/FetchBackend.kt@7b34a03a910d:62-64)
  • Rate per 1000 same-version crash reports: 159.0 = 0.43, 159.0.1 = 269.99; 412 reports from 23 installations on build 20261102144711. (brief: crash rate by version on release)
  • Uptime under 60 s: 367/412 (89%) from build 20261102144711 on, vs 65/392 (17%) on older builds. (facets uptime interval=60 split_at_build=20261102144711, release, 30d)
  • The signature predates the bump (first seen in build 20181001155545; 392 release reports on older builds in the last 30 days), so the bump raised the rate of an existing crash rather than creating it. (brief signature age; facets version, release, 30d)
  • Hardware-error share is 0% (bit-flip annotations and Raptor Lake CPUs). (brief hardware-error share)

Alternatives considered:

  • Hardware defect artefact: not supported -- 0% bit-flip and 0% Raptor Lake share; a step at one version boundary is the shape of a software change.
  • General memory pressure unrelated to the build: disfavored -- the rate stepped 628x at the 159.0 to 159.0.1 boundary, and the crash moved to early uptime.
  • Other changesets in the window (e.g. d9e45e0110f6 okio fix, 7b34a03a910d remote-settings update): not supported -- not checked in detail, and none of them touch viaduct's body buffering; the remote-settings data update could in principle change a startup response size and is unresolved.

Worth checking first:

  • Is the pre-sizing exactly as on mozilla-central in the shipped AS 159.0.2 artifact? Read FetchBackend.kt at the application-services v159.0.2 tag.
  • Which endpoint triggers it, and does it send a large or bogus Content-Length (e.g. a remote-settings attachment or Merino/Nimbus payload fetched at startup)? Check the Breadcrumbs annotation and the Java exception message ("Failed to allocate a N byte allocation") in several 159.0.1 reports.
  • Fix: cap initialBufferSize (e.g. min(contentLength, 256 KiB)) and let ByteArrayOutputStream grow, then ship it in an AS point release and bump Fenix release; a unit test with a response advertising Content-Length: 2147483647 and a small body would cover it.

:bdk, can you have a look please?

Posted automatically by Clouseau, which analyses release crashes with an LLM. Nothing above was written or checked by a human.

This is just a new signature for https://bugzilla.mozilla.org/show_bug.cgi?id=1992618 after that change. Overall the OOM errors seem to be going down, but they're still happening. That the pre-allocate buffer change only mitigates some of the errors, it doesn't fix the root cause(s). One cause that we know we have to fix is large sync allocations because we don't batch sync requests like on Desktop. I kind of suspect there's some other things happening in Fenix, but I don't have any strong evidence.

Status: NEW → RESOLVED
Closed: 19 days ago
Duplicate of bug: 1992618
Flags: needinfo?(bdeankawamura)
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.