When an async task panics, what is the right behavior ?
-
kill just the task; nothing else affected
-
kills entire program
-
undefined behavior
?
When an async task panics, what is the right behavior ?
kill just the task; nothing else affected
kills entire program
undefined behavior
?
Never on purpose in Rust.
IIRC, usually one of two things happen:
std::panic::catch_unwind
, which will then print the panic message.After which, it's up to the runtime as to whether the whole program fails or not.
Actually three.
panic = "abort"
mode, so the whole process is getting terminated. This is easier way to handle unexpected errors if the application already is fail safe/horizontally scaled. Usually the process will be re-launched by external mechanisms like systemd.In tokio:
Again, like std::thread
's JoinHandle
type, if the spawned task panics, awaiting its JoinHandle
will return a JoinError
`.
What the right behavior is for your application will depend on the application. For example, a web server would probably want the first behavior, but I can also imagine cases that want the second.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.