You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Better document that process::exit does not result in a clean shutdown #28058
The documentation states If a clean shutdown is needed it is recommended to only call this function at a known point where there are no more destructors left to run., however simply running it when no more destructors are left to run does not guarantee a clean exit. For example, output buffers are not flushed, as opposed to normal program termination. There might be other things that process::exit does not do that normal program termination does that I'm not aware of. These too should be documented. Or at the least, the documentation should not imply that if you run process::exit when there are no more destructors left to run, you get a clean exit.
Furthermore, process::exit should not be recommended as a mechanism for simply setting the exit code. env::set_exit_status was deprecated with the message Deprecated since 1.2.0: use process::exit instead, then removed. process::exit is simply not a good alternative. There are valid reasons for setting the exit code without abormal program termination.
Examples:
Incorrect command line argument: Print help, set exit status to non-zero. Clean exit.
File stated in command line argument does not exist. State this to the user, set exit status to non-zero. Clean exit.
changed the title [-]Better document lack of clean shutdown with process::exit[/-][+]Better document that process::exit does not result in a clean shutdown[/+]on Aug 28, 2015
Activity
[-]Better document lack of clean shutdown with process::exit[/-][+]Better document that process::exit does not result in a clean shutdown[/+]sfackler commentedon Aug 28, 2015
Which output buffers are not flushed? We register atexit handlers to take care of the global stdout buffer: https://github.com/rust-lang/rust/blob/master/src/libstd/io/lazy.rs#L53, and stderr is unbuffered.
crumblingstatue commentedon Aug 28, 2015
fn main() { print!("Hi!"); }results in "Hi!",fn main() { print!("Hi!"); std::process::exit(0); }results in no output.sfackler commentedon Aug 28, 2015
That seems like a bug in rt::atexit: #28065
steveklabnik commentedon Sep 4, 2015
Given that the bug has been fixed, I'm going to give this a close. Please let me know if that's still wrong.