Anyone have good examples of common Rust *runtime* footguns?
Reposted from
Andrew Lilley Brinker
It's tough because I feel like Rust footguns are "I can't get it to compile" rather than "it compiles and then does something monstrously wrong."
Comments
I think there have been optimizations that improved this situation in the past year or so. Not sure how much this is still an issue.
My mind went "huh. Endless recursion?" and then "huh but objects on the stack?" but then it ends up being some object the compiler can barely name.
If you're using Tokio as your executor, tokio-console is very useful and can help catch big futures that may be a risk for future stack limit problems. It'll flag futures over a threshold size.
https://github.com/tokio-rs/console
If you're using a Tokio mutex to maintain invariants, those invariants can be violated if a future is dropped at a yield point while the lock is held.
Here's an example!
afaik all the big frameworks are designed to handle this failure mode but i mention it because i think this still counts as a run time footgun?
I know Dropshot in Rust explicitly *doesn't* do "global handlers" that other frameworks commonly support to do things like this automatically, which is an interesting choice! https://docs.rs/dropshot/latest/dropshot/#what-about-generic-handlers-that-run-on-all-requests
we have a home rolled solution for this at the moment and I'd love if we didn't need it
I could be wrong though!
2. No "Drop" guarantee": yeah... I still wish Rust could make linear types work
Opentelemetry is a notorious offender.
It's a big hammer of a flag though.
by putting the implementation of the statics alongside a public API of global functions inside of its own crate, you can semver the statics independently. which gets rid of a lot of breakage ime.
Oh no
See https://github.com/rust-lang/rfcs/pull/3251
The solution for us was to use spawn_blocking *if* we detect that the current thread is a Tokio runtime thread.
Casting with βas Tβ can panic as well.
8 paragraph tangent about what it means that rust doesn't have a standard.
Also, itβs explicitly an aside. It literally says βaside.β You can skip it
I have adhd and this is something I would do.
Character limit discourages nuance, sorry.
what it *does* do is truncate, which can also be problematic.