News for hackers. Stuff that matters.
Re:Go Statement Considered Harmful (2018) by kodah on Friday March 19, 2021 @12:34PM (#26515357)
I don't think that's true. A panic in a goroutine should shut down the goroutine but not the main thread.

Did this change at some point?

Re:Go Statement Considered Harmful (2018) by hexmiles on Friday March 19, 2021 @02:48PM (#26516995)
if not catched in a recover() a panic when reach the top of the stack of the gorutine always cause a crash. I did not changed, as far i know is this way at least since 1.0
Re:Go Statement Considered Harmful (2018) by kodah on Friday March 19, 2021 @04:16PM (#26517761)
https://goplay.tools/snippet/am2vcq5JYFr

This is an example I made. Can you show how that would change to cause the problem you're describing?

Re:Go Statement Considered Harmful (2018) by alex_studer on Friday March 19, 2021 @04:48PM (#26518023)
It looks like maybe the goroutine in that example doesn't actually get a chance to run before the program stops. If the main function lasts longer, then you'll see the effect of the panic. See https://goplay.tools/snippet/8SFlFkZ2P0y

Also, see the Go spec: https://golang.org/ref/spec#Handling_panics

> Next, any deferred functions run by F's caller are run, and so on up to any deferred by the top-level function in the executing goroutine. At that point, the program is terminated and the error condition is reported, including the value of the argument to panic.

It looks like, assuming it makes it to the top of the current goroutine, then it should be killing the whole program.

Re:Go Statement Considered Harmful (2018) by kodah on Friday March 19, 2021 @05:55PM (#26518508)
Yeah, very interesting. it seems highly inconsistent even when using a waitgroup: https://goplay.tools/snippet/X2c7lZGTqww

Personally I don't use panics or deal in them that much, mainly because stack traces with multiple goroutines are unbelievable. I much prefer errors.

Re:Go Statement Considered Harmful (2018) by GauntletWizard on Friday March 19, 2021 @11:54PM (#26520698)
Your use of the waitgroup is off; Because the Add instruction is inside the goroutine, it may not run until after wg.Done is called, which will return immediately.

Still, that made it less flaky for a bit, but the it printed again! And I realized what else is going on: There's actually time between when the deferred functions are executed and the program exits! Which is fascinating, but unlikely to matter in practice. It brings me to another question: do deferred statements still get called when there's a panic on a different goroutine? And the answer seems to be no; adding a deferred print to the main function does not print.

Re:Go Statement Considered Harmful (2018) by kodah on Sunday March 21, 2021 @10:48AM (#26530841)
You're right about the Add(1) and defer. defer in itself is pretty interesting in how it's called. Basically there's the main body of your function and then a list of things to do before return, of which defers get added to. So, your theory is correct.

I think intuitively I probably knew that a panic in a goroutine will shut down the main thread, it just didn't occur logically to me when I read it; which is an interesting paradox. Maybe that's a me-thing though.