Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpClient GET Api is failing with {System.IO.IOException: Connection reset ---> Java.Net.SocketException: Connection reset error in .NET MAUI Android #26147

Closed
VenkataReddyDesiReddy opened this issue Nov 27, 2024 · 4 comments
Labels
platform/android 🤖 s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working

Comments

@VenkataReddyDesiReddy
Copy link

VenkataReddyDesiReddy commented Nov 27, 2024

Description

HttpClient GET API is failing in .NET MAUI(.NET 8.0) which is working in Xamarin.Forms
Below is the sample code for your reference:

CancellationTokenSource cancellationToken = new CancellationTokenSource(60000);
using (FileStream _fileStream = new FileStream(filePath, FileMode.Open))
{
    using (StreamContent _streamContent = new StreamContent(_fileStream))
    {
        HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, Uri_UpgradeStart);
        _streamContent.Headers.ContentLength = Int32.Parse(fileInfo.FileSize);
        requestMessage.Content = _streamContent;
        **var responseMessage = httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, cancellationToken.Token).ConfigureAwait(false);**
        if (responseMessage.StatusCode == HttpStatusCode.OK)
        {
            System.Diagnostics.Debug.WriteLine("Uploading upgrade success");
        }
        _fileStream.Close();
        _streamContent.Dispose();
    }
}

The line var responseMessage = httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, cancellationToken.Token).ConfigureAwait(false); is throwing exception

**{System.IO.IOException: Connection reset
 ---> Java.Net.SocketException: Connection reset**
   at Java.Interop.JniEnvironment.InstanceMethods.CallVoidMethod(JniObjectReference instance, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:line 20370
   at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String encodedMember, IJavaPeerable self, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:line 66
   at Java.IO.OutputStream.Write(Byte[] b, Int32 off, Int32 len) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Java.IO.OutputStream.cs:line 163
   at Android.Runtime.OutputStreamInvoker.Write(Byte[] buffer, Int32 offset, Int32 count) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/OutputStreamInvoker.cs:line 108
  --- End of managed Java.Net.SocketException stack trace ---
java.net.SocketException: Connection reset
	at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:121)
	at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
	at com.android.org.conscrypt.ConscryptEngineSocket$SSLOutputStream.writeToSocket(ConscryptEngineSocket.java:762)
	at com.android.org.conscrypt.ConscryptEngineSocket$SSLOutputStream.writeInternal(ConscryptEngineSocket.java:736)
	at com.android.org.conscrypt.ConscryptEngineSocket$SSLOutputStream.write(ConscryptEngineSocket.java:699)
	at com.android.okhttp.okio.Okio$1.write(Okio.java:78)
	at com.android.okhttp.okio.AsyncTimeout$1.write(AsyncTimeout.java:157)
	at com.android.okhttp.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:177)
	at com.android.okhttp.okio.RealBufferedSink.write(RealBufferedSink.java:47)
	at com.android.okhttp.internal.http.Http1xStream$FixedLengthSink.write(Http1xStream.java:290)
	at com.android.okhttp.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:177)
	at com.android.okhttp.okio.RealBufferedSink$1.write(RealBufferedSink.java:199)

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.100 SR10

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

@VenkataReddyDesiReddy VenkataReddyDesiReddy added the t/bug Something isn't working label Nov 27, 2024
@vitek-karas
Copy link
Member

/cc @simonrozsival

@simonrozsival
Copy link
Member

@VenkataReddyDesiReddy would it be possible to share a standalone repro project that makes requests against some public server so I can repro this on my side? It will be hard to do without having access to your server.

It seems suspicious that you are sending content to your server in a GET request. I'm not sure if that is supported.

One thing you might try is to use the managed HTTP handler. To try this, just add this snippet to your project file:

<PropertyGroup>
    <UseNativeHttpHandler>false</UseNativeHttpHandler>
</PropertyGroup>

@StephaneDelcroix StephaneDelcroix added platform/android 🤖 s/needs-repro Attach a solution or code which reproduces the issue labels Nov 27, 2024
Copy link
Contributor

Hi @VenkataReddyDesiReddy. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@dotnet-policy-service dotnet-policy-service bot added the s/no-recent-activity Issue has had no recent activity label Dec 3, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback to reproduce the issue but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 8, 2025
@dotnet-policy-service dotnet-policy-service bot removed the s/no-recent-activity Issue has had no recent activity label Jan 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform/android 🤖 s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants