bugthesystem / FireSharp

An asynchronous cross-platform .Net library for Firebase
The Unlicense
690 stars 146 forks source link

ReceiveThread and SendThread cause high CPU usage due to System.IO exception #127

Open botradingblog1 opened 5 years ago

botradingblog1 commented 5 years ago

first, thanks for the great library, which has been very useful.

We are currently facing an issue that when using FireSharp library listeners as part of a Windows service, the service generates high CPU usage that seems to occur when the network connection of the server or the Firebase database service is disrupted.

Our thread dumps have shown that the worker threads are executing SendThread and ReceiveThread so we believe the while(true) loops inside those methods are triggering the high CPU usage.

Have you noticed these issues? Do you have a recommendation on how to address them?

Any suggestions greatly appreciated.

Here the stack traces from the thread dumps: System.dll!System.Collections.Concurrent.BlockingCollection.TryTakeWithNoTimeValidation [External Code] [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] [Managed to Native Transition] mscorlib.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout, bool exitContext) mscorlib.dll!System.Threading.SemaphoreSlim.WaitUntilCountOrTimeout(int millisecondsTimeout, uint startTime, System.Threading.CancellationToken cancellationToken) mscorlib.dll!System.Threading.SemaphoreSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) System.dll!System.Collections.Concurrent.BlockingCollection.TryTakeWithNoTimeValidation(out FirebaseSharp.Portable.Messages.FirebaseMessage item, int millisecondsTimeout, System.Threading.CancellationToken cancellationToken, System.Threading.CancellationTokenSource combinedTokenSource) System.dll!System.Collections.Concurrent.BlockingCollection.TryTake(out FirebaseSharp.Portable.Messages.FirebaseMessage item, int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) FirebaseSharp.Portable.dll!FirebaseSharp.Portable.BlockingQueue.Dequeue(System.Threading.CancellationToken cancel) FirebaseSharp.Portable.dll!FirebaseSharp.Portable.FirebaseNetworkConnection.SendThread(System.Threading.CancellationToken cancel) mscorlib.dll!System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start(ref System.Canon stateMachine) FirebaseSharp.Portable.dll!FirebaseSharp.Portable.FirebaseNetworkConnection.SendThread(System.Threading.CancellationToken cancel) FirebaseSharp.Portable.dll!FirebaseSharp.Portable.FirebaseNetworkConnection.Connect.AnonymousMethod20_0() mscorlib.dll!System.Threading.Tasks.Task.InnerInvoke() mscorlib.dll!System.Threading.Tasks.Task.Execute() mscorlib.dll!System.Threading.Tasks.Task.ExecutionContextCallback(object obj) mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) mscorlib.dll!System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() [Native to Managed Transition] [External Code]


System.dll!System.Collections.Concurrent.BlockingCollection.TryTakeWithNoTimeValidation [External Code] [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] [Managed to Native Transition] mscorlib.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout, bool exitContext) mscorlib.dll!System.Threading.SemaphoreSlim.WaitUntilCountOrTimeout(int millisecondsTimeout, uint startTime, System.Threading.CancellationToken cancellationToken) mscorlib.dll!System.Threading.SemaphoreSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) System.dll!System.Collections.Concurrent.BlockingCollection.TryTakeWithNoTimeValidation(out FirebaseSharp.Portable.Messages.FirebaseMessage item, int millisecondsTimeout, System.Threading.CancellationToken cancellationToken, System.Threading.CancellationTokenSource combinedTokenSource) System.dll!System.Collections.Concurrent.BlockingCollection.TryTake(out FirebaseSharp.Portable.Messages.FirebaseMessage item, int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) FirebaseSharp.Portable.dll!FirebaseSharp.Portable.BlockingQueue.Dequeue(System.Threading.CancellationToken cancel) FirebaseSharp.Portable.dll!FirebaseSharp.Portable.FirebaseNetworkConnection.SendThread(System.Threading.CancellationToken cancel) mscorlib.dll!System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start(ref System.Canon stateMachine) FirebaseSharp.Portable.dll!FirebaseSharp.Portable.FirebaseNetworkConnection.SendThread(System.Threading.CancellationToken cancel) FirebaseSharp.Portable.dll!FirebaseSharp.Portable.FirebaseNetworkConnection.Connect.AnonymousMethod20_0() mscorlib.dll!System.Threading.Tasks.Task.InnerInvoke() mscorlib.dll!System.Threading.Tasks.Task.Execute() mscorlib.dll!System.Threading.Tasks.Task.ExecutionContextCallback(object obj) mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) mscorlib.dll!System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() [Native to Managed Transition] [External Code]

guiltm commented 3 years ago

same problem, did you get any solution?

guiltm commented 3 years ago

1 week and my code are working without that issue. I will send a PR.