-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macOS - sleep inhibiting #9548
macOS - sleep inhibiting #9548
Conversation
* It test a Windows method we don't use. * The test did not discover any issue on macOS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what is the actual fix idea here. It seems like a huge refactor.
To run It's certainly not a huge refactor. There is just a new common base class for linux & mac task. |
I am not sure that timing is causing the problem here. If I caffeinated the system every 5 seconds and asked to stay awake for a minute then the end result should be to stay awake. Anyway, your test will show if this makes sense. Can you reproduce the original issue on your system?
It seems to be. 7 files modified. As a reviewer, it takes time to see what is the actual change. |
I tried this approach because Clement mentioned it here #9339 (comment).
I can try again to reproduce it in the afternoon. So far I had issues with reproducing it though.
True but that's why there are commits explaining it step by step. |
I am testing this. |
This PR solves the issue I had while testing #9339 |
WalletWasabi.Tests/UnitTests/Helpers/PowerSaving/BaseInhibitorTaskTests.cs
Outdated
Show resolved
Hide resolved
Awesome, one step ahead - let's review this. |
So this PR doesn't solve the issue even with the last commit because of this: https://github.com/zkSNACKs/WalletWasabi/blob/0ee438d7a1fe86f69ce4e0a3a9760b85275f3b19/WalletWasabi/Services/SleepInhibitor.cs#L98 if (TaskFactory is not null) With this, the PR solves the issue and kills properly the caffeinate process when needed. Notes:
|
Keep it up, guys - this is important! |
@turbolay You are right. Thanks for pointing it out. I have verified that with the latest commit, I can see
Yes, removed. Thanks.
Now it should have an effect.
We are certainly interested in this scenario because we don't want to: kill WW and leave |
Is this ready to review? (it is still a draft) |
Yes |
tACK Just a note: When I force kill WW, caffeinate is not killed. |
I've been researching this and unfortunately on macOS there is no One advanced idea how to tackle this is to start a bash script like this on macOS machines: caffeinate -i & # Start caffeinate as a background process.
processPID=$! # Get the PID of the caffeinate process.
wait {Environment.ProcessId} # Wait until Wasabi Wallet is stopped (can this work?)
kill $processPID # Kill the caffeinate process. We get here only if somebody kills his WW app instance forcefully. but then we have a different problem: We can't kill the Another idea was to just start
but that does not work for me. I'm not entirely sure why it does not work. Resources |
# Set up a trap to run the "killall caffeinate" command when the parent process is killed
trap "killall caffeinate" SIGINT SIGTERM https://ss64.com/osx/trap.html @kiminuo WDYT? EDIT: So I tested it, it does not work and I think that's because it's a shell built in command and we have I tried: FileName = "/bin/bash",
Arguments = "-c 'trap \"killall caffeinate\" SIGINT SIGTERM'", In that case the |
|
yes 2022-12-06_06-50-34.mp4 |
@kiminuo this script is similar to the one you posted but should work as intended (just change process name): #!/usr/bin/env bash
# Trap the killall so we kill the background caffeinate when Process.Kill() is executed in C#
trap "killall caffeinate" SIGINT SIGTERM
caffeinate -i &
CAFFEINATE_PID=$!
# Loop until wasabi is killed without sending SIGINT SIGTERM
while [ -n "$(pgrep Wasabi)" ]
do
sleep 1
done
# Kill caffeinate in case that wasabi was forced killed
kill $CAFFEINATE_PID && exit
If it doesn't work directly we should just add the |
Hm, wouldn't this work? #!/usr/bin/env bash
caffeinate -i &
processPid=$!
trap "kill -9 ${processPid}" SIGINT SIGTERM
wait ${processPid} It seems conceptually better. It's not tested but I'm interested if you like the concept. btw: |
Seems like same idea but better code. |
I used both of our suggestions to make this code, which I tested and it works in all cases: Pass the SIGTERM bool in Process.Kil()Add the bool in the wrapper: public virtual void Kill(bool gracefully = false)
{
Process.Kill(gracefully);
} Then call with the bool set as True: Process.Kill(true); Launch the processvar wasabiProcessId = Environment.ProcessId;
string scriptPath = "/path/to/script.sh";
startInfo.FileName = "bash";
startInfo.Arguments = $"{scriptPath} {wasabiProcessId}"; Pass as argument the PID of Wasabi's process Bash script#!/usr/bin/env bash
caffeinate -i &
caffeinatePid=$!
trap "kill -9 $caffeinatePid" 0 SIGINT SIGTERM
while [ -n "$(grep $1)" ]
do
sleep 1
done The script launches caffeinate in the background, waits for parent process (wasabi) to end. Wasabi now kills with SIGTERM so trap will work if Wasabi want to pause caffeinate. If wasabi is forced kill (SIGKILL received), the bash script will leave the loop and exit with code 0, trap will also catch that and kill caffeinate. I didn't manage to run the script hardcoded (not relying on Just a final note: Using the PID like this is considered unreliable because for whatever reason it might change in long running systems. If you think that this problem is concerning in a way, we should either use the process name or when calling |
Nice! @kiminuo can you make this happen? caffeinate works fine with the small script. |
Yeah, I will try. @turbolay Thanks for this
I don't think this is true. Do you have a source of this information? I mean process ID does not change, it's an identifier of the process, you don't have anything else to recognize the process. The only important thing is that after some time the process ID can be re-used and that would be indeed bad if we killed a different process. |
You are right, it cannot change but can be reused. |
@molnard I coordinated with kimi, he already did it! |
Contributes (hopefully) to #9339
Based on:
Not tested, I can test it in the afternoon