HttpClient Timeout on Stream causing Subscribe to Retry
See original GitHub issueI 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:
- Created 6 years ago
- Reactions:1
- Comments:5
Top GitHub Comments
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?