I searched a lot for this and i couldn’t find a clear answer, if i have a running system (say an HTTP server) what do i do if one of my functions panics ?, a lot of people seem to say that you should have some middleware or similar mechanism that catches the panic, logs the error and terminates the request with a 500 error response.
I primarily used Node js in the past, and the best practice there is to log the error and exit the process with an error code.
So what’s the “Go” way to deal with such a situation ?.
Wouldn’t it be possible to leak resources (memory, file descriptors) if you didn’t have deferred calls that freed used resources (closed file descriptors, and connections).
Yes, if you do not use defer to handle cleaning up, then that cleanup won’t happen in the case of a panic, but you should be using defer to clean up those resources in the first place.