-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
std.process.cleanExit so we can not clean up our cake and eat it too #6395
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
Comments
As part of this: * add std.process.cleanExit. closes #6395 - use it in several places * adjust the alignment of text in `zig build --help` menu * Cache: support the concept of "unhit" so that we properly keep track of the cache when we find out using the secondary hash that the cache "hit" was actually a miss. Use this to fix false negatives of caching of stage1 build artifacts. * fix not deleting the symlink hash for stage1 build artifacts causing false positives. * implement support for Package arguments in stage1 build artifacts * update and add missing usage text * add --override-lib-dir and --enable-cache CLI options - `--enable-cache` takes the place of `--cache on` * CLI supports -femit-bin=foo combined with --enable-cache to do an "update file" operation. --enable-cache without that argument will build the output into a cache directory and then print the path to stdout (matching master branch behavior). * errors surfacing from main() now print "error: Foo" instead of "error: error.Foo".
I think this has a potential to be a footgun if this function is not called from const std = @import("std");
fn foo() void {
return std.process.cleanExit();
}
pub fn main() !void {
foo();
std.debug.print("helo\n", .{});
} On debug builds, this prints |
I don't think this is a good idea. Afaik if you don't clean up your sockets nicely, it will have effects when restarting the same program (afaik: if your process crashes, you cannot rebind the same socket for some minutes unless you use SO_REUSEADDR and then it's only possible with the same program). I don't think this is desirable as a default behaviour for release builds. Also cleaning up resources with |
I was also thinking about this, but should that really be in a I do agree that it looks fishy. I'd rather call it |
Alternative solutions to
For 1, the new definition would mean that calling a In 2, this can be done: pub fn main() !u8 {
// instead of: std.process.exit(1);
return 1;
} |
@joachimschmidt557 see #2198 (comment) for case (1). |
i ran into a use case for this here: https://github.com/andrewrk/groovebasin/blob/b27b4e02baa13e88d601e8008fd9d59b55d7ff22/tools/paste-js.zig#L59-L60 It does me no good to meticulously deallocate all my memory when the process is going to exit anyway. Is there a reason to close my open file descriptors before my process exits? Pretty sure the OS will do that for me. (I don't have any unflushed output buffers to worry about.) I'm not an expert on SO_REUSEADDR, but I don't see any evidence in the documentation that it's affected by the application closing the socket before exiting. Someone please correct me if I'm wrong. |
The name "cleanExit" is one problem with this proposal. At first glance, that sounds like it's going to run a bunch of Another problem is the intended way to use this function is unintuitive. You're supposed to return it from main, but the function signature doesn't indicate that. In order to make this function signature not a footgun, we could change the way |
I think the intended usage pattern of this is too subtle for it to go into std. It's 4 lines, no problem for application developers to provide. Thanks all |
Calling code would look something like this:
The text was updated successfully, but these errors were encountered: