|
|
|
|
|
by preseinger
1244 days ago
|
|
The impact of a specific panic does not extrapolate to the impact of all panics, and my claim is not falsified by such an example. Panics are defined by the language to represent unrecoverable errors. func (x *Thing) Method() {
x.somethingThatPanics()
x.somethingThatAssumesTheAboveDidntPanic()
}
Recovering from a panic thrown by Method invalidates the state of the Thing which threw that panic. If that Thing is shared among concurrent actors, the entire program state is invalidated. |
|
You're adding preconditions to your claim.
> the entire program state is invalidated.
No, the state represented by a connected graph of variables accessible by the concurrent actors is tainted. This is hardly "the entire program state". Often it's just a few cache entries.
Also, see my first, most important, bullet point:
"* Make sure you support properly unrolling the stack."
Which means a request to Thing errored out, but it never enters an invalid state. If you fail at that, all bets are off. But then you're dealing with a mediocre codebase anyway.
And finally, let me rewrite your example to something, that I see much more often in real life code, which problematic _even without concurrent actors_ because somethingThatAssumesTheAboveDidntReturnAnError might do horrible things all by themself:
func (x *Thing) Method() {
x.somethingThatReturnsAnError()
x.somethingThatAssumesTheAboveDidntReturnAnError()
}