-
Notifications
You must be signed in to change notification settings - Fork 40
Avoid allocating in pre_exec closure
#777
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
Conversation
44219e4 to
5feec54
Compare
Public API changes for crate: brush-coreChanged itemsPerformance Benchmark Report
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is Test Summary: bash-completion test suite
|
|
Thanks for identifying this issue and contributing a fix, @purplesyringa! The latest version of your change seems reasonable given the constraints. (I read your linked issue and see how many other projects you believe are affected. If you're willing to share, I'm curious to know how you came across this and what ideas you have on how we could mechanically catch these sorts of challenges in the future. (I know that pre_exec is unsafe so I recognize that some risk was already implied.)) |
|
First of all, I'm confused why the bot mentions
My girlfriend asked me to review her code. I thought
That's a good question. A clippy lint might help, but it's not clear how to decide which functions are allowed to be called, since we don't have effects and there's no annotations of that sort, so it'd just be a blacklist. Something that I think might be worthwhile is to disable the global allocator in |
That's right. Once the checks re-ran, it updated the compat report accordingly. We really only use the
Absolutely--I'm one of those. I'm aware of the risks of allocation between
It sounds like it's worth a conversation, but agree that such checks may be overly restrictive for some platforms. I like the idea of a wrapper for debugging/validation. I haven't used any of them before, but I see on |
Error::otherallocates memory (see rust-lang/rust#148971). This is bad in multi-threaded programs, which brush AFAIK is. If the fork occurs while the allocator lock is held by another thread, deadlocks can occur, since there's no one left in the new process to unlock the mutex. I do not believe this is UB, and modern libc offer protections against this issue, but this isn't POSIX-compliant and should preferably be avoided.Luckily,
nixprovides a non-allocatingimpl From<Errno> for std::io::Error, and it passes the correct error code through to the parent process, instead of using the default-EINVALlikeError::other.I'm not sure how to best integrate this into your project. I changed the return type of
move_self_to_foregroundto usestd::io::Error, which works, but feels hacky. If you have a better idea, feel free to apply your own patch and close this PR.