Rem0o / FanControl.Releases

This is the release repository for Fan Control, a highly customizable fan controlling software for Windows.
Other
14.17k stars 443 forks source link

Crashes after sleep #231

Closed pelifix closed 3 years ago

pelifix commented 3 years ago

When PC is waking up after sleep, FanControl crashes with this error: image

1) Please note I do not use "Start with Windows".

2) log.txt has this error, I don't know if it's related: ~~08.05.2021 17:12:43: Unhandled exception in FanControl v1.0.0.0 08.05.2021 17:12:43: System.ObjectDisposedException: Closed. at HidSharp.Platform.SysRefCountHelper.HandleAcquireIfOpenOrFail() at HidSharp.Platform.Windows.WinHidStream.Write(Byte[] buffer, Int32 offset, Int32 count) at LibreHardwareMonitor.Hardware.Controller.Nzxt.KrakenX3.SoftwareControlValueChanged(Control control) at LibreHardwareMonitor.Hardware.Control.set_ControlMode(ControlMode value) at LibreHardwareMonitor.Hardware.Control.SetSoftware(Single value) at FanControl.ViewModels.ControlViewModel.PeriodicUpdate() at FanControl.Domain.ApplicationClock.DoActions() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)~~

cydRabbit commented 3 years ago

Same issue but I am using 'Start with Windows' option enabled.

2021-05-21 오후 12:11:23: Unhandled exception in FanControl v1.0.0.0 2021-05-21 오후 12:11:23: System.ObjectDisposedException: Closed. 위치: HidSharp.Platform.SysRefCountHelper.HandleAcquireIfOpenOrFail() 위치: HidSharp.Platform.Windows.WinHidStream.Write(Byte[] buffer, Int32 offset, Int32 count) 위치: LibreHardwareMonitor.Hardware.Controller.Nzxt.KrakenX3.SoftwareControlValueChanged(Control control) 위치: LibreHardwareMonitor.Hardware.Control.set_ControlMode(ControlMode value) 위치: LibreHardwareMonitor.Hardware.Control.SetSoftware(Single value) 위치: FanControl.ViewModels.ControlViewModel.PeriodicUpdate() 위치: FanControl.Domain.ApplicationClock.DoActions() --- 예외가 throw된 이전 위치의 스택 추적 끝 --- 위치: System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 위치: System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 위치: System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Rem0o commented 3 years ago

Do you have an NZXT Kraken X3? Do you have CAM or similar running to control that?

pelifix commented 3 years ago

Yes I have the NZXT Kraken X53. But I have never installed any software that came with it, feel they are to bloated. So no other software is running.

cydRabbit commented 3 years ago

I have NZXT Kraken X73. but I don't use NZXT CAM. never installed. Other software that I am using RTSS and Afterburner only.

pelifix commented 3 years ago

Some updates:

Is there anything I can do to turn on more detailed logging?

pelifix commented 3 years ago

Something wild is happening after PC wakes up, the FanControl.exe process is using an excessive amount of handles! Over 16 million handles! This is after wake-up, just before the process cashes: image

When I restart FanControl, and before PC goes to sleep, I see a more normal number: image

Let me know it there is anything I can do in helping logging/debugging this?

daninko commented 3 years ago

I am having a similar issue as pelifix with occasional crashes and excessive CPU usage after waking my computer from sleep. I have the NZXT X53 cooler, but I have not had CAM running while I've been using the FanControl software.

pelifix commented 3 years ago

Yeah, FanControl still crashes on every single wake-up. I am now running version 86, no changes to behavior.

I just did a quick test, and used the "handle.exe" cli tool from SysInternals, and got this result:

D:\Christer\OneDrive\Tools>handle -p fancontrol -s

Nthandle v4.22 - Handle viewer
Copyright (C) 1997-2019 Mark Russinovich
Sysinternals - www.sysinternals.com

Handle type summary:
  ALPC Port       : 19
  Desktop         : 1
  Directory       : 3
  EtwRegistration : 203
  Event           : 10766716
  File            : 47
  IoCompletion    : 38
  IoCompletionReserve: 1
  IRTimer         : 8
  Key             : 83
  Mutant          : 22
  Section         : 38
  Semaphore       : 49
  Thread          : 56
  Timer           : 3
  Token           : 2
  TpWorkerFactory : 4
  WaitCompletionPacket: 49
  WindowStation   : 2
Total handles: 10767344

As you can see more than 10mil handles of type 'Event'. This is a few seconds before the process crashes. Before going to sleep mode, I have around 432 Event Handles.

pelifix commented 3 years ago

Ok, just tested older releases, and found out:

@Rem0o , would you mind taking a look at what changed between release 74 and 76? Thanks!

Rem0o commented 3 years ago

What changed is now the driver is closed then reopened after a wake from sleep. I optimized that behavior in V86 so that it closes before going to sleep and reopens after resume from sleep. So technically, it's just like you closed fan control before going to sleep and reopening it after it wakes up.

Sleep is FanControl's worst nightmare because during sleep, the BIOS resets every config you applied. Every strategy I've tried doesn't work for at least somebody, I have yet to find a bullet-proof strategy that works for every single system. V86 is my best shot at it.

pelifix commented 3 years ago

I see, but are we sure the problem is in the driver? I've tried to find a way to trigger the problem without going to sleep and I finally managed:

I can now reproduce the problem by doing this:

I then instantly see the handle leak in Task Manager (or using handle.exe), crashes after 10-30 seconds.

No sleep - wake-up needed to trigger the problem.

Rem0o commented 3 years ago

@pelifix in that case, does it still log a problem with the NZXT handle ?

pelifix commented 3 years ago

No, nothing in the log file.

Rem0o commented 3 years ago

If you download the lastest LHM lib dll from https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/actions/runs/964965830 ( Download the full 5mb artifact ) and you swap that out into FanControl, same issue?

pelifix commented 3 years ago

I can't get this to work. I replace (overwrite) the files. Then FanControl will nor start. No error message, just won't start...

Rem0o commented 3 years ago

@pelifix only the LibreHardwareMonitorLib.dll

pelifix commented 3 years ago

yes, same issue.

I replaced the dll, removed CACHE file, started FanControl, all is fine. Then I click "Refresh sensor detection..." and I see the handle leak and crash after 30 sec.

cydRabbit commented 3 years ago

If you download the lastest LHM lib dll from https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/actions/runs/964965830 ( Download the full 5mb artifact ) and you swap that out into FanControl, same issue?

It works for me. I did replace LibreHardwareMonitorLib.dll and run FanControl successfully. so I'll use it more times and leave result here.

pelifix commented 3 years ago

@cydRabbit , what is working for you? Did you even have the same problem as I am having? Remember this is not about the error in the log file.

cydRabbit commented 3 years ago

If you download the lastest LHM lib dll from https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/actions/runs/964965830 ( Download the full 5mb artifact ) and you swap that out into FanControl, same issue?

It works for me. I did replace LibreHardwareMonitorLib.dll and run FanControl successfully. so I'll use it more times and leave result here.

hmm.. still crashing after wakeup from sleep mode :(

cydRabbit commented 3 years ago

@cydRabbit , what is working for you? Did you even have the same problem as I am having? Remember this is not about the error in the log file.

yes, I have same problem like you. FanControl.exe crash after wakeup with error alert window, right?

Aphykit2006 commented 3 years ago

Hello In my case, after sleep mode : I have either an error message or a blank screen with the temperature at 0. after sleep

Log.txt log.txt

Fan Control V87, Windows 10 regards

[Edit] One test : Quit FC add all rights in FC folder. delete log.txt and Cache Delete default configuration.json Run updater.exe

Go in sleep mode. (with start menu) Ok at wakeup
Go in Hibernation => rundll32.exe powrprof.dll,SetSuspendState 0,1,0 at wakeup :

second sleep

Test normal suspend state with start menu again => OK Hibernation is the problem ??

TEST : Go to the Start Menu and open an elevated Command Prompt by typing cmd.exe, right clicking and choosing Run as administrator. Type the following command: powercfg -hibernate off

=> ok a wakeup (one test only)

jackoboy9 commented 3 years ago

Same issue here.

kamolot2k commented 3 years ago

Hi,

same here fan

Test did nothing here - same result v87, Win10 20H2

Rem0o commented 3 years ago

No error logs or anything? (log.txt)

The error you see is your config restoring, but the underlying issue is most likely because the driver couldn't initialize properly or can't read any sensor.

XanderTek commented 3 years ago

Unfortunately V89 does not seem to have resolved this. When it comes back from sleep, the "Handles" start increasing until it gets into the millions, then it crashes with an applications error, same as what Pelifix showed above.

Latest LHM lib.dll also doesn't seem to make a difference.

I do have a workaround: I used task scheduler to trigger on sleep (Kernel-Power, Event ID: 42), which runs a .bat to taskkill FanControl. And then a separate task that triggers on wake (Power-Troubleshooter, Event ID:1), which starts FanControl back up. Admittedly a little clunky, but this seems to avoid the crashes entirely.

Rem0o commented 3 years ago

The only constant in all of this is the NZXT Kraken stuff. There has to be a leak in the implementation, most likely highlighted by my Close() / Open() cycle I do in FanControl.

Not to sure the stream in there is handled correctly, especially with the thread and its while loop/try-catch messy looking code. https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/blob/master/LibreHardwareMonitorLib/Hardware/Controller/Nzxt/KrakenX3.cs

XanderTek commented 3 years ago

I do have a Kraken X63. But I've installed zero NZXT software. I control it via https://github.com/liquidctl/liquidctl, which, if I understand correctly, doesn't leave anything running in the background.

Just tested, and LHM does the exact same thing after waking from sleep: the number of handles growing into the millions, then it crashes. I'll see if there's an equivalent issue over there, and submit one if not.

Rem0o commented 3 years ago

I do have a Kraken X63. But I've installed zero NZXT software. I control it via https://github.com/liquidctl/liquidctl, which, if I understand correctly, doesn't leave anything running in the background.

Just tested, and LHM does the exact same thing after waking from sleep: the number of handles growing into the millions, then it crashes. I'll see if there's an equivalent issue over there, and submit one if not.

That's great news you could reproduce it there, any chance you can debug C# with the source code there?

cydRabbit commented 3 years ago

This is my latest log file. log.txt

Updated latest version but still crashing after sleep. I hope the log file to help to resolve this problem :)

cydRabbit commented 3 years ago

FanControl has no longer crash after sleep with V90 update. I think this problem has resolved.

Rem0o commented 3 years ago

@cydRabbit I did nothing about this problem for V90. It probably has an external factor.

pelifix commented 3 years ago

Great! Version V90 seams to be working fine. I can cycle through sleep - wakeup without any issues. The handle count stays stable, typically just below 1000.

@Rem0o, does V90 contain an updated LibreHardware component? Maybe they fixed something?

Anyway, I will monitor this for a couple of days and if everything is fine I'll close this issue. Thanks everyone!

pelifix commented 3 years ago

Ok, I've been running on version V90 and V91 for a while. No problems, cycling through sleep -> wake-up working without issues. Problem seams to be fixed in LHM. I'm closing this issue now, thanks everyone!