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

ReadAsync/SendAsync app crash #73

Open
stesvis opened this issue Sep 17, 2020 · 3 comments
Open

ReadAsync/SendAsync app crash #73

stesvis opened this issue Sep 17, 2020 · 3 comments
Labels

Comments

@stesvis
Copy link

stesvis commented Sep 17, 2020

Hello,

I have many crash reports in AppCenter that are related to the GetAsync() and SendAsync() methods.

ModernHttpClient
ByteArrayListStream.ReadAsync (System.Byte[] buffer, System.Int32 offset, System.Int32 count, System.Threading.CancellationToken cancellationToken)
ModernHttpClient
ProgressStreamContent+ProgressStream.ReadAsync (System.Byte[] buffer, System.Int32 offset, System.Int32 count, System.Threading.CancellationToken cancellationToken)
System.IO
Stream.CopyToAsyncInternal (System.IO.Stream destination, System.Int32 bufferSize, System.Threading.CancellationToken cancellationToken)
System.Net.Http
StreamToStreamCopy+<>c.b__1_0 (System.Threading.Tasks.Task completed, System.Object innerSource)
System.Threading.Tasks
ContinuationTaskFromTask.InnerInvoke ()
System.Threading.Tasks
Task.Execute ()
System.Net.Http
HttpContent.LoadIntoBufferAsyncCore (System.Threading.Tasks.Task serializeToStreamTask, System.IO.MemoryStream tempBuffer)
System.Net.Http
HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts)

I have the relevant code lines inside a try/catch, but still it causes a crash (sometimes, when the connection times out i think):

try 
{
    // ...
    var response = await WebApiClient.GetAsync(url);
    var responseJson = await response.Content.ReadAsStringAsync();
    // ...
}
catch (Exception ex) 
{
    // ... handle it
}

Where WebApiClient is a global HttpClient instance:

public static HttpClient WebApiClient = new HttpClient(new NativeMessageHandler(false, new TLSConfig()))
        {
            Timeout = TimeSpan.FromSeconds(45),
            BaseAddress = new Uri(Misc.Constants.ApiUrlsBase.BaseUrl),
        });

Why would it make the app crash even tho i am using try/catch? Like I said, the error is related to timeouts:
image

I hope that someone may help me figure this out, thank you.

@alexrainman
Copy link
Owner

The max timeout you can set is 30 seconds (by platform specific limitations). Can you provide a reproduction demo?

@alexrainman alexrainman added the bug label Oct 7, 2020
@stesvis
Copy link
Author

stesvis commented Oct 7, 2020

After further testing i was able to simulate poor internet connection and reproduce this exception.
I think it's just related to weak internet.

@petro2050
Copy link

I think the implementation of #72 can help with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants