http.ListenAndServe() ERR_EMPTY_RESPONSE on panic

I am learning golang and playing around with http.ListenAndServe().

If one of my http Handler functions does a panic, the browser gets ERR_EMPTY_RESPONSE.

Is this the way real world http handling is implemented?

I thought that a http 500 “internal server error” gets returned on a panic.

Related example: Go by Example: HTTP Servers

IIRC it depends on when your handler panics. If headers have already been written and the panic happens then, then the response can’t be changed to a 500 anymore.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.