On Aug 20, 2014 6:12 PM, "Alan Shreve" <al...@inconshreveable.com> wrote:
> Is it impossible for all panics? Or is it only unsafe to do so in cases where the runtime internally caused the panic? If it is the former, what makes it impossible to do so?
it might be holding a lock, or the memory might be corrupted. please consider how you're going to document the new feature: what is safe to run as a handler?
the only reliable way is to run your application as a child process and monitor its output.
On Aug 20, 2014 7:41 PM, "Alan Shreve" <al...@inconshreveable.com> wrote:
> Thanks for clarifying. Sorry I’m a little slow here but could you help me understand a little bit more?
how are you going to document this proposed feature? we can't just say it's a best effort service. you can't allocate memory, can't defer (it allocates memory), can't use network (might take lock), can't start goroutines (allocates memory), can't take lock (might deadlock), can't start child process (takes the ForkExec lock), ...(there are more that you can't safely do, these are just from the top of my head) when running the handler.
i've heard program that tries to flush the log just before the program exits goes wrong and the program never exits.
Running another process is not 100% reliable either; the hardware could fail, the operating system could fail, or there could be a bug in your monitoring process. No crash reporting mechanism is ever 100%, one must choose some set of given primitives and assume them to be “safe”.
Not 100% reliable, but certainly gives a much bigger chance to do something reasonable than in a process which is already going down crashing and burning. You might want to have a look at:
http://en.wikipedia.org/wiki/Crash_reporter
- that's apparently how Mozilla and Google approach such situations, among others.
Given that strong opinion on what's supposed to happen on a panic, I'm
curious about your opinion on how net/http doesn't actually stop the
application when a panic happens, but rather just logs it and hopes
the rest of the system continues working well. Isn't that an analogous
situation?
Ethan
On Aug 25, 2014 6:18 PM, "Ethan Burns" <burns...@gmail.com> wrote:
> Does that mean we should consider it dangerous to recover a panic then continue on?
it's dangerous to recover _all_ panics and _always_ continue, esp. for the runtine panics.
Does that mean we should consider it dangerous to recover a panic then continue on?
Ethan
In essence, you should only recover from panics that you are expecting (ie, you wrote the call to panic()), not to handle buggy code.
I can count on one hand the number of times I have used recover in real code.
Callback for APIs that do not accept a function that returns an error.
Thanks, Andrew. That makes me a bit sad. I suspect most of the catch-your-own-panic uses of recover are ugly conveniences for things like error handling in parsers. It always comforted me knowing that recover's true reason for existence was the net/http use case: avoiding a server crash when one client hits an inevitable bug. It's sad to crash an entire server when an off-by-one error causes an index out of bound (which I assume is perfectly safe to recover). However, given Rob's comment on how unstable the system is on a panic and Russ's regret about net/http's behavior, I'm now led to believe that I should just let the server crash. Or am I being overly pessimistic?
Ethan
It's sad to crash an entire server when an off-by-one error causes an index out of bound (which I assume is perfectly safe to recover). However, given Rob's comment on how unstable the system is on a panic and Russ's regret about net/http's behavior, I'm now led to believe that I should just let the server crash.
It's 2024 now. I wonder if anything has improved. I totally get the reasons why recovering from an unknown-panic is plain dangerous. However, think of the scenario of a service that handles tons of parallel requests. There must be a way to isolate misbehaving requests from the others.
Back in 2018, I posted this question: https://stackoverflow.com/questions/50418919/how-to-prevent-go-program-from-crashing-after-accidental-panic. My team was considering Go to write a credit card transaction service which heavily depended on third party (possibly buggy) code. Even if it was 100% in house code, we were just afraid that a bug in a single request could bring the whole service down, causing a lot of problems for the other non-related requests. We ended up picking C# (due to team's background, but it could have been Java too). We placed an outermost try-catch-all for each request. This isolation mechanism was good enough. We found bugs and fixed them. Over time, the service matured really well.
For the scenario, is there a recommended way of writing a Go service which isolates requests?
--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-dev/CAPBqLKG7tYFSvjEua6Hcpk19u%2BL4hcNCwDxjV8B3vBzd5vEqbg%40mail.gmail.com.
On Jan 31, 2024, at 2:59 PM, Igor Cananea <icca...@gmail.com> wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-dev/CAEX6X_CzmK4fY-sGSt%2Bj_yv7euSPGyM%2BL_OhHWdvhLk5VAnxrw%40mail.gmail.com.
On Jan 31, 2024, at 8:01 PM, Igor Gatis <igor...@gmail.com> wrote:
On Jan 31, 2024, at 8:59 PM, Igor Gatis <igor...@gmail.com> wrote:
On Jan 31, 2024, at 9:50 PM, Robert Engels <ren...@ix.netcom.com> wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-dev/15490FA4-85CA-460E-81DA-582B52471C82%40ix.netcom.com.