So I kind of knew of this behavior and I stumbled upon it before but actually I am not sure what is the best way to solve / debug the issue.
So on production I am observing on occasion requests that are being sent to our system, and I can see the initial Logger line for the request as being handled by the app:
12:59:19.614 request_id=Fnc9RXabbAmFCZ0AAAdG [info] GET /
but for these requests I am missing the log entry that a response was sent, i.e. no line like:
12:59:19.624 request_id=Fnc9RXabbAmFCZ0AAAdG Sent 200 in 10ms
As far as I understand, this means the Cowboy handler process exitted before it’s registered “before_send” callback is executed, which is being installed here by Plug.Logger:
So, I have stumbled upon the situation that my requests fail, process exits, and I have no entry in logs, nor in AppSignal (we use Appsignal.Plug) as it’s just handling throws and exceptions, but not exits.
Since Cowboy is built not on OTP primitives, we don’t see the usual crash reports for these processes either. They seem to silently fail.
Now, I need to debug and fix the issue but also monitor for this not happening in the future. So I have several questions:
Am I missing something that on Cowboy / Plug / Phoenix level would detect, log and report these mysterious exits? I think the answer is “no” and that situation is simply not handled by the above.
The implementation should be as per this blog post (of mine) from 2 years ago, i.e. start a monitoring process for each request handler in a plug and log / report exits or is there some ready to use piece of infrastructure / library I should be using instead? When web requests fail in Elixir and Phoenix | AmberBit Sp. z o. o.