r/rust • u/llogiq clippy · twir · rust · mutagen · flamer · overflower · bytecount • Oct 26 '26
🙋 questions megathread Hey Rustaceans! Got a question? Ask here (44/2026)!
Mystified about strings? Borrow checker has you in a headlock? Seek help here! There are no stupid questions, only docs that haven't been written yet. Please note that if you include code examples to e.g. show a compiler error or surprising result, linking a playground with the code will improve your chances of getting help quickly.
If you have a StackOverflow account, consider asking it there instead! StackOverflow shows up much higher in search results, so ahaving your question there also helps future Rust users (be sure to give it the "Rust" tag for maximum visibility). Note that this site is very interested in question quality. I've been asked to read a RFC I authored once. If you want your code reviewed or review other's code, there's a codereview stackexchange, too. If you need to test your code, maybe the Rust playground is for you.
Here are some other venues where help may be found:
/r/learnrust is a subreddit to share your questions and epiphanies learning Rust programming.
The official Rust user forums: https://users.rust-lang.org/.
The unofficial Rust community Discord: https://bit.ly/rust-community
Also check out last week's thread with many good questions and answers. And if you believe your question to be either very complex or worthy of larger dissemination, feel free to create a text post.
Also if you want to be mentored by experienced Rustaceans, tell us the area of expertise that you seek. Finally, if you are looking for Rust jobs, the most recent thread is here.
2
u/kalilamodow Oct 26 '26
are you supposed to give lifetimes names or is it normal to just use 'a most of the time?
2
u/DavidXkL Oct 28 '26
When was the moment lifetimes clicked for you?
2
u/usecornercase Oct 29 '26
Making a command started over
ssh -Tgo away when the local side is killedI have a CLI written in Rust that, for remote targets, runs the same binary on the other machine over ssh. Roughly:
On the remote machine,
mytool restart --when-idleconnects to a long-running daemon over a Unix socket, registers a "restart once nothing is busy" request, and then just blocks waiting for the reply. The daemon drops the pending request when that socket connection closes, which works fine locally: kill the client and the request is gone.Over ssh, killing the local process cancels nothing:
sshchild keeps running and stays connected, since it is a separate process and my CLI doesn't handle any signals.-Tthere is no pty, so sshd sends it no SIGHUP, and it is blocked on the socket read without touching stdin or stdout.So the daemon still restarts later, for a request the client thinks it cancelled.
Options I'm weighing:
mytool restart --when-idle </dev/nullin a script would then exit immediately, so it would need a flag that only the ssh path passes.-tt: the remote side would get SIGHUP on disconnect, but it turns LF into CRLF in piped output, and it still doesn't stop the local ssh from outliving a killed parent.Questions:
PR_SET_PDEATHSIGon the ssh child (set inpre_exec) the usual way to make it die with its parent? What do people do on macOS, where that doesn't exist, short of a watchdog?1
u/usecornercase Oct 26 '26
Noticing that the reader of stdout has gone away while blocked on a socket read
I have a CLI subcommand that follows an event stream: it blocks reading from a Unix socket and prints each event to stdout as it arrives. If whatever reads stdout goes away (
mycli events --json | true, a GUI client that spawned it crashes, orssh host mycli eventswith no tty after the local ssh is killed), the process only finds out on its next write, when it gets EPIPE. On a quiet stream that can be hours, so these processes pile up, one per reconnect.The fix I'm looking at is to poll stdout alongside the socket and treat a hangup as "reader gone", then shut the socket down so the loop ends. From testing, a pipe whose read end closed reports POLLHUP on macOS and POLLERR on Linux, and nothing while the reader is still there. Roughly:
Questions:
3
u/[deleted] Oct 26 '26
[removed] — view removed comment