Skip to content

[release/11.0.1xx] [tests] Backport bounded-copy upload test - #13751

Merged
jonathanpeppers merged 1 commit into
release/11.0.1xxfrom
jonathanpeppers-backport-bounded-copy-upload-test
Nov 24, 2026
Merged

jonathanpeppers merged 1 commit into
release/11.0.1xxfrom
jonathanpeppers-backport-bounded-copy-upload-test

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 7ddbbb0ae0745e91032a2c4ff0cc442e83170ba3

Dimension Assessment Rationale
Change confidence 8/10 ↑ Same test diff as #13110.
↓ Android workload unavailable locally.
Diagnosis confidence 8/10 ↑ Bounded writes avoid a large JNI allocation.
↓ No local reproduction.
Evidence fit 7.5/10 ↑ Reported CI failure includes a Java heap OOM.
↓ Not confirmed with this change in CI.

Backport of the AndroidMessageHandlerUploadTests change from #13110.

UploadConnectionResetThrowsHttpRequestException crashes with OutOfMemoryError on CI emulators, because MemoryStream.CopyToAsync writes the 16 MiB body in one call. Copy in chunks instead.

Context: #13716

Validation: build.cmd failed on locked files. dotnet-local.cmd build tests\Mono.Android-Tests\Mono.Android-Tests\Mono.Android.NET-Tests.csproj --no-restore -nodeReuse:false -v:minimal failed with NETSDK1147: the Android workload is missing. The device test was not run.


Pull Request
title and
description
should follow the
commit-messages.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

Backport only the AndroidMessageHandlerUploadTests change from 9d70f2f (#13110). Bound each upload write to avoid exhausting small Java heaps.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 14:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the test-only bounded-copy upload change.

No open issues 🎉

What changed in this PR

Backports the bounded-copy upload test change to release/11.0.1xx to address emulator out-of-memory crashes tracked in #13716. The change is limited to test code.

Changes:

  • Uses BoundedCopyMemoryStream for the connection-reset test’s 16 MiB request body.
  • Overrides asynchronous copying to write in buffer-sized chunks instead of one large write across JNI, while forwarding cancellation.
File Description
tests/​Mono.Android-Tests/​Mono.Android-Tests/​Xamarin.Android.Net/​AndroidMessageHandlerUploadTests.cs Adds and uses a bounded-copy stream to limit individual upload writes.

Review effort: Balanced

@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Nov 24, 2026
@jonathanpeppers
jonathanpeppers enabled auto-merge (squash) November 24, 2026 18:34
@jonathanpeppers

Copy link
Copy Markdown
Member Author

@dalexsoto review

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 7ddbbb0a against release/11.0.1xx at bdbe0a66 (merge base 6066c2d2). This is a static, read-only review; nothing was built or run.

The test file at this head is byte-identical to main after #13110, and it starts from the same blob, so this is an exact backport. The only target commit since the merge base (#13571) is a dependency update and doesn't touch this file.

I traced the upload path on this branch to confirm the override is actually reached:

  • AndroidMessageHandler.SetupRequestBody sets fixed-length streaming, so the Java connection doesn't buffer the body.
  • WriteRequestContentToOutput calls ReadAsStreamAsync and then CopyToAsync (httpConnection.OutputStream, 4096, cancellationToken) (AndroidMessageHandler.cs:1074-1075). StreamContent's read-only wrapper forwards CopyToAsync with the buffer size, so BoundedCopyMemoryStream.CopyToAsync runs with 4096.
  • Each OutputStreamInvoker.Write goes through JNIEnv.NewArray for the whole managed buffer, so this replaces one 16 MiB Java allocation with 4 KiB ones.

The asserted exception chain and the Position == 0 rewind come from unchanged handler code, the 16 MiB body is still far larger than the server reads before the reset, and the file compiles under this branch's settings (it already uses primary constructors; LangVersion is latest).

Non-blocking:

  • The override isn't strictly needed: MemoryStream.CopyToAsync already falls back to Stream's chunked loop for subclasses, so the subclass alone would bound the writes. Keeping it identical to main is reasonable.
  • #13716 pairs this with #13310 (SharedPreferencesTest heap pressure), which isn't on release/11.0.1xx yet, so that out-of-memory crash may still show up on this branch until it is backported too.

LGTM.

@jonathanpeppers
jonathanpeppers merged commit 329d684 into release/11.0.1xx Nov 24, 2026
45 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-backport-bounded-copy-upload-test branch November 24, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants