CPU spinning when streaming
See original GitHub issueI get this issue after running with streaming for about 12 hours where my process will start using all CPU on thread.
When I attach to process or break all with CPU profiling, it always points to this method Firebase.Database.Streaming.FirebaseSubscription`1.<ReceiveThread>d__14.MoveNext()
I might be reading the callstack wrong, but it always seem centered around .ReadLine
When I got the source code attached, I got into this loop. Is it possible that this loop can start spinning the cpu without any break?
This is from: FirebaseSubscription.cs
using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false)) using (var reader = this.client.Options.SubscriptionStreamReaderFactory(stream)) { while (true) { this.cancel.Token.ThrowIfCancellationRequested();
line = reader.ReadLine()?.Trim();
if (string.IsNullOrWhiteSpace(line))
{
continue;
}
var tuple = line.Split(new[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();
switch (tuple[0].ToLower())
{
case "event":
serverEvent = this.ParseServerEvent(serverEvent, tuple[1]);
break;
case "data":
this.ProcessServerData(url, serverEvent, tuple[1]);
break;
}
if (serverEvent == FirebaseServerEventType.AuthRevoked)
{
// auth token no longer valid, reconnect
break;
}
}
}
Also, how often do these keep-alive messages get sent out? It seems like every few seconds.
I’m running Debug builds with Visual Studio 2017 15.3 and .NET 4.6.1 I’ve noticed the other thread with re-authenticating… but it doesn’t seem to be the case, also I’ve added the re-auth code that was suggested.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9
Top GitHub Comments
I managed to get a bit more data out of a case when it was spinning CPU cycles.
It was stuck here and the event was “CANCEL”. I’m not sure it makes sense to me according to the docs, https://www.firebase.com/docs/rest/guide/retrieving-data.html#section-rest-streaming According to the code, it should cause a Unauthorized exception but I don’t see it anywhere… and this also happened within 1minute of running.
Firebase.Database.FirebaseException: Exception occured while processing the request. Url: https://db.firebaseio.com/messages/emails/pending/.json?orderBy=“sendDateTime”&endAt=“1503392326.31061”&auth=****** Request Data: Response: —> System.Threading.Tasks.TaskCanceledException: A task was canceled. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Net.Http.HttpClient.<FinishSendAsync>d__58.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable
1.ConfiguredTaskAwaiter.GetResult() at Firebase.Database.Query.FirebaseQuery.<OnceSingleAsync>d__7
1.MoveNext() in C:\Projects\firebase-database-dotnet-master\src\Firebase\Query\FirebaseQuery.cs:line 88 — End of inner exception stack trace — at Firebase.Database.Query.FirebaseQuery.<OnceSingleAsync>d__71.MoveNext() in C:\Projects\firebase-database-dotnet-master\src\Firebase\Query\FirebaseQuery.cs:line 98 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() at oevent.busi.NotificationBusi.<GetPendingEmailNotifications>d__10.MoveNext() in3 month without that problem. I sent a PR. https://github.com/step-up-labs/firebase-database-dotnet/pull/254