-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
High CPU usage when running in disowned mode #11795
Comments
Reproduced for me with a build from master. The terminal thread is calling Lines 422 to 424 in 650c53d
So the terminal thread is in a tight loop retrying the |
Thank you so much for looking into this! So it means: Line 423 in 650c53d
Should be changed to: if (!retval || (retval == -1 && (errno == EBADF || errno == EINVAL || errno == EIO))) |
Maybe. Maybe not. I did confirm that as expected making such a change corrects the CPU usage in the case at hand. One worry is that Given that, I did not propose a fix as I thought it best this be handled by developers familiar with the history of problems with this source. |
The original logic was introduced in 4b5c3ea#diff-5430e3916d2be16faed7c318993e5f26cefae4a686da8f699af4c67814dbf68eR194 and later modified in 6023843#diff-5430e3916d2be16faed7c318993e5f26cefae4a686da8f699af4c67814dbf68eR405 to fix #5833. The author of both commits, wm4, does not seem to be around anymore.
On Linux:
It seems therefore pretty normal to stop trying and break out of the loop. @Akemi, sorry to ping you directly, but we might need your guidance here. If you agree with the proposed solution above, I can prepare a pull request. |
for me this would seem fine at first glance. though this change doesn't only affect macOS but linux too and i am not too familiar with this part of the code. i think it's best to open a PR and let someone with more linux experience look over it too. |
This commit fixes mpv-player#11795. If parent terminal is closed while mpv is running, read(2) starts returning EIO, resulting in an infinite loop using 100% of the CPU. This commit makes sure we don't loop needlessly if read(2) returns EIO.
This commit fixes mpv-player#11795. If parent terminal is closed while mpv is running, read(2) starts returning EIO, resulting in an infinite loop using 100% of the CPU. This commit makes sure we don't loop needlessly if read(2) returns EIO.
This commit fixes mpv-player#11795. If parent terminal is closed while mpv is running, read(2) starts returning EIO, resulting in an infinite loop using 100% of the CPU. This commit makes sure we don't loop needlessly if read(2) returns EIO.
the reason for checking `EBADF|EINVAL` specifically is unknown. but it's clearly not working as intended since it can cause issues like mpv-player#11795. instead of checking for "bad errors" check for known "good errors" where we might not want to break out. this includes: * EINTR: which can happen if read() is interrupted by some signal. * EAGAIN: which happens if a non-blocking fd would block. `tty_in` is _not_ non-blocking, so EAGAIN should never occur here. but it's added just in case that changes in the future. Fixes: mpv-player#11795 Closes: mpv-player#11805
the reason for checking `EBADF|EINVAL` specifically is unknown. but it's clearly not working as intended since it can cause issues like #11795. instead of checking for "bad errors" check for known "good errors" where we might not want to break out. this includes: * EINTR: which can happen if read() is interrupted by some signal. * EAGAIN: which happens if a non-blocking fd would block. `tty_in` is _not_ non-blocking, so EAGAIN should never occur here. but it's added just in case that changes in the future. Fixes: #11795 Closes: #11805
fixes regression caused by 2e7fcc5 where it wouldn't receive terminal input if the process was foregrounded later on like this: $ mpv something.mp4 & $ fg ref: mpv-player#11795
Looks like breaking on I've added a different fix in #11975 to deal with that. It would be nice if someone on mac can test it out and confirm everything still works fine. |
Important Information
0.30.0
,0.34.1
.Reproduction steps
After exiting the terminal, Activity Monitor reports CPU
110%
, Preventing SleepYes
.Expected behavior
Closing the terminal that ran mpv should have no impact on the CPU usage, even when paused.
Actual behavior
CPU is above 100%.
Log file
output.txt. Made with
-v -v --log-file=output.txt
.This doesn't seem related to #11667.
The text was updated successfully, but these errors were encountered: