Skip to content

Chapter 18.2: abort & unwind - non-illustrative example #1957

@Feliksas

Description

@Feliksas

The code example in the chapter does show the technique of compiling differrent code paths depending on profile configuration, but does not illustrate the actual difference between unwind and abort strategies for panic!, thus the example is completely decoupled from the chapter's topic. Providing some examples of behavioural difference when different panic strategies are configured would be more helpful. As per post by HadrienG on rust-lang.org forum:

"Unwinding panics enable an application thread to shut down in a relatively clean way. All allocated system resources are reclaimed, all application objects are properly dropped, and so on. In addition, panics stop at the boundary of the offending thread, rather than killing the whole application process. All of this means that if all objects have sensible destructors, application recovery from a panic is possible, although difficult.

<...>

With aborts, there is no such possibility of application recovery. As soon as some piece of code aborts, the application process is instantly killed, which means that achieving fault tolerance requires much more elaborate multi-process designs. In addition, because resource destructors are not run, the whole system can be left in an inconsistent state, which means that restarting the application may be highly non-trivial.

To summarize, you should only enable panic-on-abort in situations where you really do not care about your application crashing instantly AND potentially also trashing any hardware/OS state that it was manipulating at crash time along the way."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions