question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HttpClient Timeout on Stream causing Subscribe to Retry

See original GitHub issue

I have setup this observable (commented out filters because they would fail when data structure would change on firebase. See issue )

This code runs fine, however it seems the subscribe will keep firing after ~1:40mins and the only way to get around this is to filter on already ‘processed’ objects by way of a ‘processed’ field on the object.

var lastUpdate
  var fbBookings = fbHelper.Client.Child("bookings").OrderBy("updatedAtTS").StartAt((long)lastUpdate);
                    var observable = (from b in fbBookings.AsObservable<BookingsFireBaseModelUpdate>()
                                          //where b.Object != null && !string.IsNullOrEmpty(b.Object.attendanceCountUpdate)
                                          //|| !string.IsNullOrEmpty(b.Object.commentUpdate)
                                          //|| !string.IsNullOrEmpty(b.Object.waiverFormUpdate)
                                      select b).RetryWithBackoffStrategy(10);

                    var subs = observable
                   .Subscribe(async (x) =>
                   {
                      //processing
                   });

After doing some digging, I found that I repeatedly receive A task was canceled exception after ~1:40mins. Which then restarts the stream connection to firebase and hence the behaviour observed above occurs.

at System.Net.Http.HttpClientHandler.WebExceptionWrapperStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.Http.DelegatingStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.StreamReader.ReadBuffer()
   at System.IO.StreamReader.ReadLine()
   at Firebase.Database.Streaming.FirebaseSubscription`1.<ReceiveThread>d__14.MoveNext() in C:\dev\Tutorials\firebase-database-dotnet-master\src\Firebase\Streaming\FirebaseSubscription.cs:line 111

Seems to throw at this line line = reader.ReadLine()?.Trim(); Ive checked, it doesnt seem to be counting against the connections in firebase…which is weird at first glance.

After more investigation it seems to be related to the default timeout on the httpclient doing the initial stream listening itself. See timeout docs on httpclient here https://msdn.microsoft.com/en-us/library/system.net.http.httpclient.timeout(v=vs.110).aspx

After adding the timeout in the FirbaseSubscription.cs to httpClient.Timeout = Timeout.InfiniteTimeSpan; the exceptions stopped occuring.

Has anyone else experienced this behaviour? It seems to only happen in the Azure WebJob im running this in (continuous, NoAutomaticTrigger). Possibly a threading issue? I have no problems with the same code in a console app…

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
IsaackRasmussencommented, Sep 26, 2017

This sound very similar to the issue I’m seeing. #94 But I’m not using Azure WebJobs just normal Windows Services.

Googling the timeout property, I see other devs saying its needed for streaming or it will timeout despite heartbeats. Interesting… I’ll try this myself

0reactions
guiltmcommented, Aug 6, 2020

Isso soa muito semelhante ao problema que estou vendo. # 94 Mas não estou usando os WebJobs do Azure, apenas os serviços normais do Windows.

Pesquisando na propriedade timeout, vejo outros desenvolvedores dizendo que é necessário para streaming ou o tempo limite excede os batimentos cardíacos. Interessante … vou tentar isso sozinho

This sound very similar to the issue I’m seeing. #94 But I’m not using Azure WebJobs just normal Windows Services.

Googling the timeout property, I see other devs saying its needed for streaming or it will timeout despite heartbeats. Interesting… I’ll try this myself

did you get any solution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Retrying HttpClient Unsuccessful Requests
The Timeout property on HttpClient, HttpClient.Timeout , will act as an overall timeout across all retries combined. To impose a timeout-per-try ...
Read more >
HttpClient does not retry HTTP/1.1 request if TCP ...
It is ok to retry the request even if it's the first request on the connection -- due to connection pooling changes, connections...
Read more >
Transient timeouts and the retry rabbit hole (.Net 4.5)
1st Lesson: If we want to retry a TaskCanceledException caused as a result of a transient timeout, but not as a result of...
Read more >
Getting burnt with HttpClient
LEARNING: HttpClient has a default timeout set to 100 seconds. So you better have a good connection or download small files.
Read more >
Retry failed HTTP requests in Angular | by Kevin Kreuzer
If the source Observable, which is our HTTP request, fails, the retryWhen operator is called. Inside the callback, we get access to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found