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.

CPU spinning when streaming

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
IsaackRasmussencommented, Sep 1, 2017

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.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Firebase.Database.Query.FirebaseQuery.<OnceSingleAsync>d__71.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.TaskAwaiter1.GetResult() at oevent.busi.NotificationBusi.<GetPendingEmailNotifications>d__10.MoveNext() in

1reaction
guiltmcommented, Nov 9, 2020

3 month without that problem. I sent a PR. https://github.com/step-up-labs/firebase-database-dotnet/pull/254

Read more comments on GitHub >

github_iconTop Results From Across the Web

Possible CPU Issues While Streaming : r/Twitch
Hey, there! So whenever I stream, my cpu usage very frequently goes to max usage and the stream lags immensely, this happens often...
Read more >
CPU spike to 99% sometimes 100% when streaming
I have been trying to stream fortnite for the past couple months and everytime I stream I start stuttering and freezing up especially...
Read more >
CPU Overheating Whilst Streaming - Linus Tech Tips
After around 5 minutes of gaming and streaming simultaneously, the CPU starts to spike every 5-10 seconds and causes fps drops and lag...
Read more >
High CPU frequency when watching Twitch streams
The CPU ramping to full speed is completely normal. The overheating is most likely due to inadequate cooling. Also, Chrome is using about...
Read more >
Troubleshooting: Stream performance issues related to CPU
If you are having problems with a stuttering stream or sluggish computer performance on your workstation, you are most likely overloading ...
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