rust-lang / rust-lang/rust-by-example

Chapter 18.2: abort & unwind - non-illustrative example

Open
#1,957 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Handlebars
Stars
8.1k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

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."

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Chapter 18.2 and compare its current code example with the chapter's explanation of panic strategies. Add examples that visibly demonstrate the behavioral difference between configured unwind and abort strategies, using the cited resource as context; done means the example illustrates the chapter's actual topic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.