-
Notifications
You must be signed in to change notification settings - Fork 82
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
Sudo high cpu usage after terminal is closed #841
Comments
@blazp7 does this happen with OG sudo as well? Edit: I can't reproduce this while downloading a large file and killing alacritty on gnome. |
I remember we fixed this related issue during the Berlin Meeting: #263. We could also have a look at the relevant code where the potential loop might be. Of course, @pvdrz, if we fix this we are getting really close to your favorite scenario |
Note: the example you cite is |
@squell the only place where something similar could happen would be here: https://github.com/memorysafety/sudo-rs/blob/9e7a4c4fa48ec6e411e5cb3b2ae0a4258227a856/src/exec/event.rs#L222-L243 But that would mean that there aren't any file descriptors being polled or that the polling is failing consistently, which I find very unlikely as all the signal handling is done via sockets that are polled there. |
It seems that just exiting a terminal where recording.webm |
Only Might or might not be relevant, dont know if this is the default behaviour but someone from nixos matrix chat said: |
(Yes, Does it happen with |
No. After i close the terminal that has an active |
I'm suspecting an interaction between |
Alright, well i learned that i should use |
That's very useful info (I didn't know shadow-utils also packaged a |
I have commands showing the same symptoms. They look like:
Self-built sudo-rs 0.2.2 on Arch.
Never seen this behavior before installing sudo-rs. But It's worth noting that I updated many system packages at the same time. So other variables could be relevant, but I highly doubt it. Is that the same issue? I know Rust if you think fiddling with/debuging a specific part of the code would help. |
@AppleSheeple thanks for the report! It seems one of the sockets we're using is being reported as ready constantly (file descriptor 4 in your strace output) when being polled. I have a hunch this has to do with a socket on the other "side" being closed (we always use We may be handling this error improperly. I'll try to take a look at this next week. |
I had some time for a proper initial investigation (didn't get to the code yet). What's happening is that I run this stuff from a script in a terminal. But I background and detach this run. So:
fd 4 is not actually a socket. It's actually
|
I gave the code a look, and confirmed that polling here does NOT return an error: So, even if that error wasn't ignored, the issue would still be triggered. I don't think I will have the time to chase this further. |
Alright. Had some time to look at this again. This change fixes the issue for me: diff --git a/src/exec/use_pty/pipe/mod.rs b/src/exec/use_pty/pipe/mod.rs
index 7f02f06..b6046c7 100644
--- a/src/exec/use_pty/pipe/mod.rs
+++ b/src/exec/use_pty/pipe/mod.rs
@@ -7,6 +7,7 @@ use std::{
};
use crate::exec::event::{EventHandle, EventRegistry, PollEvent, Process};
+use crate::log::dev_warn;
use self::ring_buffer::RingBuffer;
@@ -58,6 +59,19 @@ impl<L: Read + Write + AsRawFd, R: Read + Write + AsRawFd> Pipe<L, R> {
&self.right
}
+ pub(super) fn tty_gone<T: Process>(&mut self, registry: &mut EventRegistry<T>) -> bool {
+ let gone = unsafe {
+ // Check if tty which existed is now gone.
+ // NOTE: errno set is EIO which is not a documented possibility.
+ libc::tcgetsid(self.left.as_raw_fd()) == -1
+ };
+ if gone {
+ dev_warn!("tty gone (closed/detached), ignoring future events");
+ self.ignore_events(registry);
+ }
+ gone
+ }
+
/// Stop the poll events of this pipe.
pub(super) fn ignore_events<T: Process>(&mut self, registry: &mut EventRegistry<T>) {
self.buffer_lr.read_handle.ignore(registry);
@@ -80,6 +94,9 @@ impl<L: Read + Write + AsRawFd, R: Read + Write + AsRawFd> Pipe<L, R> {
poll_event: PollEvent,
registry: &mut EventRegistry<T>,
) -> io::Result<()> {
+ if self.tty_gone(registry) {
+ return Ok(());
+ }
match poll_event {
PollEvent::Readable => self.buffer_lr.read(&mut self.left, registry),
PollEvent::Writable => self.buffer_rl.write(&mut self.left, registry), |
Just ran into this on another device where I forgot to install a patched version. |
Describe the bug
Frequently the
sudo
process is left running at 100% on one cpu core, after the terminal is already closed. When i hear the cpu fans i know there is atleast one sudo that i need to kill manually.To Reproduce
Steps to reproduce the behavior:
sudo su
nix shell nixpkgs#sysbench
sudo
process now starts to run at 100% on one coreExpected behavior
sudo
process doesnt torture my cpu.Environment (please complete the following information):
Additional context
I use Hyprland window manager, maybe it has something to do with how it closes apps? Or maybe nix shell causes it.
The text was updated successfully, but these errors were encountered: