From efcd007b0ce2e5a69f684dcf747f90d1a6531ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Rozs=C3=ADval?= Date: Tue, 27 Feb 2024 11:33:34 +0100 Subject: [PATCH 1/5] [Mono.Android] Do not dispose request content stream in AndroidMessageHandler (#8764) Fixes: https://github.com/xamarin/xamarin-android/issues/2901 Fixes: https://github.com/xamarin/xamarin-android/issues/4476 Fixes: https://github.com/xamarin/xamarin-android/issues/7086 Neither the `SocketsHttpHandler` nor the `iOS/macOS` `NSUrlSessionHandler` dispose the content stream, let's follow suit. --- .../AndroidMessageHandler.cs | 47 +++++++++---------- .../AndroidMessageHandlerTests.cs | 25 ++++++++++ 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs b/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs index 44883640487..26645e6fdcb 100644 --- a/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs +++ b/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs @@ -536,30 +536,29 @@ protected virtual async Task WriteRequestContentToOutput (HttpRequestMessage req if (request.Content is null) return; - using (var stream = await request.Content.ReadAsStreamAsync ().ConfigureAwait (false)) { - await stream.CopyToAsync(httpConnection.OutputStream!, 4096, cancellationToken).ConfigureAwait(false); - - // - // Rewind the stream to beginning in case the HttpContent implementation - // will be accessed again (e.g. after redirect) and it keeps its stream - // open behind the scenes instead of recreating it on the next call to - // ReadAsStreamAsync. If we don't rewind it, the ReadAsStreamAsync - // call above will throw an exception as we'd be attempting to read an - // already "closed" stream (that is one whose Position is set to its - // end). - // - // This is not a perfect solution since the HttpContent may do weird - // things in its implementation, but it's better than copying the - // content into a buffer since we have no way of knowing how the data is - // read or generated and also we don't want to keep potentially large - // amounts of data in memory (which would happen if we read the content - // into a byte[] buffer and kept it cached for re-use on redirect). - // - // See https://bugzilla.xamarin.com/show_bug.cgi?id=55477 - // - if (stream.CanSeek) - stream.Seek (0, SeekOrigin.Begin); - } + var stream = await request.Content.ReadAsStreamAsync ().ConfigureAwait (false); + await stream.CopyToAsync(httpConnection.OutputStream!, 4096, cancellationToken).ConfigureAwait(false); + + // + // Rewind the stream to beginning in case the HttpContent implementation + // will be accessed again (e.g. after redirect) and it keeps its stream + // open behind the scenes instead of recreating it on the next call to + // ReadAsStreamAsync. If we don't rewind it, the ReadAsStreamAsync + // call above will throw an exception as we'd be attempting to read an + // already "closed" stream (that is one whose Position is set to its + // end). + // + // This is not a perfect solution since the HttpContent may do weird + // things in its implementation, but it's better than copying the + // content into a buffer since we have no way of knowing how the data is + // read or generated and also we don't want to keep potentially large + // amounts of data in memory (which would happen if we read the content + // into a byte[] buffer and kept it cached for re-use on redirect). + // + // See https://bugzilla.xamarin.com/show_bug.cgi?id=55477 + // + if (stream.CanSeek) + stream.Seek (0, SeekOrigin.Begin); } internal Task WriteRequestContentToOutputInternal (HttpRequestMessage request, HttpURLConnection httpConnection, CancellationToken cancellationToken) diff --git a/tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs b/tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs index 96f66778ef3..b71ee2893da 100644 --- a/tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs +++ b/tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs @@ -98,6 +98,31 @@ async Task DoDecompression (string urlPath, string encoding, string jsonFi return true; } + [Test] + public async Task DoesNotDisposeContentStream() + { + using var listener = new HttpListener (); + listener.Prefixes.Add ("http://+:47663/"); + listener.Start (); + listener.BeginGetContext (ar => { + var ctx = listener.EndGetContext (ar); + ctx.Response.StatusCode = 204; + ctx.Response.ContentLength64 = 0; + ctx.Response.Close (); + }, null); + + var jsonContent = new StringContent ("hello"); + var request = new HttpRequestMessage (HttpMethod.Post, "http://localhost:47663/") { Content = jsonContent }; + + var response = await new HttpClient (new AndroidMessageHandler ()).SendAsync (request); + Assert.True (response.IsSuccessStatusCode); + + var contentValue = await jsonContent.ReadAsStringAsync (); + Assert.AreEqual ("hello", contentValue); + + listener.Close (); + } + [Test] public async Task ServerCertificateCustomValidationCallback_ApproveRequest () { From 37594cab8133d91ef25f2e3f9e35974ffd6717e4 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Tue, 27 Feb 2024 08:39:47 -0600 Subject: [PATCH 2/5] $(AndroidPackVersionSuffix)=preview.3; net9 is 34.99.0.preview.3 (#8765) Context: https://github.com/xamarin/xamarin-android/tree/release/9.0.1xx-preview2 We branched for .NET 9 Preview 2 from 8c7cf91f into release/9.0.1xx-preview2; the main branch is now .NET 9 Preview 3. Update xamarin-android/main's version number to 34.99.0-preview.3. --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index eb9b8dfd3c9..3f855aae763 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -36,7 +36,7 @@ * Bump first digit of the patch version for feature releases (and reset the first two digits to 0) --> 34.99.0 - preview.2 + preview.3 From 43a397fa93b7d2ad4702c8a0b048844aefaa5fec Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Feb 2024 08:44:10 -0600 Subject: [PATCH 3/5] Bump to xamarin/java.interop/main@14a9470 (#8766) Changes: https://github.com/xamarin/java.interop/compare/c825dcad8e7fe2e1ba5846a592a02f6a578db991...14a9470176b314fe521479fc75f6d9dd919abb56 * xamarin/java.interop/main@14a9470 [Java.Interop.Tools.TypeNameMappings] introduce project for net8.0 * xamarin/java.interop/main@bd793f1 [Java.Interop.Tools.TypeNameMappings] fix ToJniName() * xamarin/java.interop/main@67c079c [Java.Interop.Tools.JavaCallableWrappers] fix net8.0 targeting in XA * xamarin/java.interop/main@2197579 [Hello-NativeAOTFromJNI] Add NativeAOT sample * xamarin/java.interop/main@c8fcf70 Bump to xamarin/xamarin-android-tools@37d79c9 * xamarin/java.interop/main@56b7eeb [Java.Interop.Tools.TypeNameMappings] fix trimmer warnings --- external/Java.Interop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/Java.Interop b/external/Java.Interop index c825dcad8e7..14a9470176b 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit c825dcad8e7fe2e1ba5846a592a02f6a578db991 +Subproject commit 14a9470176b314fe521479fc75f6d9dd919abb56 From 2f4e01ec15102dd9cd922cbd833f6482d69512b5 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" <42748379+dotnet-maestro[bot]@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:43:58 -0600 Subject: [PATCH 4/5] Bump to dotnet/installer/main@d070660282 9.0.100-preview.3.24126.2 (#8763) Changes: https://github.com/dotnet/installer/compare/0a73f814e1...d070660282 Changes: https://github.com/dotnet/runtime/compare/dcc66a7ca2...99b76018b6 Changes: https://github.com/dotnet/emsdk/compare/258b51a8e5...2d3f1fe480 Updates: * Microsoft.Dotnet.Sdk.Internal: from 9.0.100-preview.2.24122.3 to 9.0.100-preview.3.24126.2 * Microsoft.NETCore.App.Ref: from 9.0.0-preview.2.24122.2 to 9.0.0-preview.2.24123.1 * Microsoft.NET.Workload.Emscripten.Current.Manifest-9.0.100.Transport: from 9.0.0-preview.2.24120.1 to 9.0.0-preview.2.24121.1 * Microsoft.NET.ILLink.Tasks: from 9.0.0-preview.2.24122.2 to 9.0.0-preview.2.24123.1 Other changes: * [tests] ignore `IncrementalFastDeployment` for now Context: https://github.com/NuGet/Home/issues/13269 Co-authored-by: Jonathan Peppers --- eng/Version.Details.xml | 16 ++++++++-------- eng/Versions.props | 8 ++++---- .../Tests/InstallTests.cs | 1 + 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index ace9f2b5381..566089db986 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -1,20 +1,20 @@ - + https://github.com/dotnet/installer - 0a73f814e19c9a239371cb732c9d1257e10fb8a2 + d070660282eb5f78497310f77093638744112e03 - + https://github.com/dotnet/runtime - dcc66a7ca25696a2326f296c3d8d3ac5a13f0524 + 99b76018b6e4edc4ce185dd5f3c5697c6941d88e - + https://github.com/dotnet/runtime - dcc66a7ca25696a2326f296c3d8d3ac5a13f0524 + 99b76018b6e4edc4ce185dd5f3c5697c6941d88e - + https://github.com/dotnet/emsdk - 258b51a8e5f5bea07766ab99d2aaa75582d1ceb9 + 2d3f1fe4807a21879cedba9d3fde8cd329fb17f2 https://github.com/dotnet/cecil diff --git a/eng/Versions.props b/eng/Versions.props index c096a719b25..6bf62dc7325 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -1,12 +1,12 @@ - 9.0.100-preview.2.24122.3 - 9.0.0-preview.2.24122.2 - 9.0.0-preview.2.24122.2 + 9.0.100-preview.3.24126.2 + 9.0.0-preview.2.24123.1 + 9.0.0-preview.2.24123.1 7.0.0-beta.22103.1 7.0.0-beta.22103.1 - 9.0.0-preview.2.24120.1 + 9.0.0-preview.2.24121.1 $(MicrosoftNETWorkloadEmscriptenCurrentManifest90100TransportVersion) 7.0.100-rc.1.22410.7 0.11.4-alpha.24119.1 diff --git a/tests/MSBuildDeviceIntegration/Tests/InstallTests.cs b/tests/MSBuildDeviceIntegration/Tests/InstallTests.cs index f25d948b44c..f1021c2d15d 100644 --- a/tests/MSBuildDeviceIntegration/Tests/InstallTests.cs +++ b/tests/MSBuildDeviceIntegration/Tests/InstallTests.cs @@ -495,6 +495,7 @@ public void LocalizedAssemblies_ShouldBeFastDeployed () [Test] public void IncrementalFastDeployment () { + Assert.Ignore ("https://github.com/NuGet/Home/issues/13269"); AssertCommercialBuild (); var class1src = new BuildItem.Source ("Class1.cs") { From 4a2179ce8831183294aaa8d18cbe2af67686ce47 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:22:52 -0500 Subject: [PATCH 5/5] Bump to xamarin/xamarin-android-tools/main@37d79c9 (#8752) Changes: https://github.com/xamarin/xamarin-android-tools/compare/a698a33aa4ffcaac90b54caf5e77236d57b0cf9e...37d79c9dcdf738a181084b0b5890877128d75f1e * xamarin/xamarin-android-tools@37d79c9: Bump LibZipSharp to 3.1.1 (xamarin/xamarin-android-tools#228) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- external/xamarin-android-tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/xamarin-android-tools b/external/xamarin-android-tools index a698a33aa4f..37d79c9dcdf 160000 --- a/external/xamarin-android-tools +++ b/external/xamarin-android-tools @@ -1 +1 @@ -Subproject commit a698a33aa4ffcaac90b54caf5e77236d57b0cf9e +Subproject commit 37d79c9dcdf738a181084b0b5890877128d75f1e