4 ms·
> It will be leaked if panic=unwind and if you use catch_panic. An uncaught panic terminates the thread. If that's the main thread the process terminates, but
by CodesInChaos 7y ago
> It will be leaked if panic=unwind and if you use catch_panic.
An uncaught panic terminates the thread. If that's the main thread the process terminates, but on other threads it continues with leaked memory, even without `catch_unwind`.
> catch_panic is not used very much.
Are you sure about that? I'd expect most multi-threaded (web)servers to continue after a panic. Otherwise any bug causing a panic (common in my experience) would force a potentially expensive restart of the server.
- steveklabnik 7y ago> If that's the main thread the process terminates, but on other threads it continues with leaked memory Yep, my bad, I simply made a mistake here. > Are you sure about that? I'd expect most multi-threaded (web)servers to continue after a panic. The two main use-cases for panics seem to be: 1. web servers 2. FFI, since panic across the boundary is UB On 1, well, this is actually a contentious point. In general, the web world has moved more and more to more and more disposable web servers. You have to be resilient to something killing your web serer process, so you need the infrastructure here anyway. Servers re-starting isn't very expensive because you have a bunch of them already, and they don't start serving requests until they're up. Of course, "defense in depth" is a good idea, so doing both makes more sense than just one, but you can't get away with just catching panics if you want a robust service. And, a lot of web servers are single threaded these days.... Regardless, while web services are a big market for Rust, they're only one thing that it does, so I still think of this as "not that popular." Maybe that's wrong :)
- CodesInChaos 7y agoA reproducible panic can easily take down your whole fleet of servers, so you'd end up with a one process per request model without planning for this. Plus if a webserver handles more than one request in parallel (affects both multi-threaded and node.js style async designs), you want to finish handling all the other requests before shutting down gracefully. In my experience with C# even exceptions caused by bugs/failed assertions (which would map to panics in rust) almost never cause issues which require a server restart. It's a bit worse in Rust, since a GC collects memory more reliably in case of errors than Rust (but even in Rust leaks should rarely happen on panic)