-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add full support for sys module (debug cowboy process state) #750
Conversation
This change provides support for the `sys` module in cowboy processes. Where possible new callbacks are as similar to existing OTP behaviours as possible. Basic HTTP handlers have two new optional callbacks: * `code_change/4` * `format_status/2` Middlewares now have the following possible return values: * `{ok, Req, Env}` * `{suspend, Module, Function, Args}` * `{system, From, Msg, Module, Req, Env, Misc}` * `{halt, Req, Env}` The `system` return value is used to handle system messages. The `Module` used must implement the `cowboy_system` callbacks: * `continue/3` * `terminate/4` * `code_change/5` And may implement the three optional callbacks: * `get_state/2` * `replace_state/3` * `format_status/2` A requirement of supporting the `sys` module is using `proc_lib`. This has the following side effects: * A `crash_report` is sent to the error logger on abnormal exit * The emulator will nolongers sends an error logger on uncaught error * Uncaught errors will nolonger have a stacktrace in exit signal
Reacting to this message only at this point.
I'm not sure what this is about. Basic HTTP handlers are uninterruptible, and have no reason to be (it's just the
Why? It's not obvious why it's necessary from just this commit message.
Why not name them
Not sure why you want |
Sorry I meant handlers in general! I will change the commit message to be clearer. These two functions will only be used if the handler is upgraded and behave exactly the same as the OTP behaviours, except
This was so middlewares (and sub protocols) could support the
I had named them
If those two functions are required (and
Sorry! I assumed it was clear because it works in the same as in OTP behaviours except the list provided in the second argument is slightly different. To borrow from the Erlang docs it is called in an OTP behaviour when:
In the case of In the later case it is used to format the state in the exit reason of the process - so ranch can log an easier to read state. As well as the changes mentioned above I will improve the commit message to explain what each callback function does. Thank you very much for the feedback! |
There is some confusion to me about what is considered "state". When you do |
This depends, I document that a middleware/sub_protocol should return The initial commit has over 350 lines added to the guide and manual, some of these might be helpful for you to understand how the callbacks work. A more detailed look at these two functions is here: https://github.com/fishcakez/cowboy/blob/e7a4045dc5c5632afbed76d39bf503e588a8f974/doc/src/guide/middlewares.ezdoc#L174-L251. The additions to the guide I mention in my opening comments is about a chapter on how to debug the handlers - rather than how to enabled a middleware/sub_protocol to be debugged, which is already in. |
For example |
Oh but |
OK I want to cut down this PR into smaller steps, each with their docs/tests, and with some time passed in between the different merges to see if feedback comes in. Let's start with a PR implementing system processes for middlewares and sub protocols. It will only force Second step would be to add the mandatory Third step would be And finally I think Thoughts? |
This sounds good to me. I think we may need to merge first 2 steps as step I will remove Env from the callback arguments/return values, leaving Req We can discuss the other points as they become relevant. On Monday, 6 October 2014, Loïc Hoguin [email protected] wrote:
|
Alright, great. I understand about 2 being important for 1 and am not convinced they should be separated either when merging so 2 commits sounds fine. |
d6b11e6
to
12a4cc5
Compare
The format_status and proper upgrades are currently not in Cowboy itself (not tested anyway). |
Closing in favor of #1134 for tracking the remaining tasks. Thanks! |
This change provides support for the
sys
module in cowboy processes. Where possible new callbacks are as similar to existing OTP behaviours as possible. This changes requires 17.0 so can only be merged into the2.0
branch, and not1.0
.To use the debugging features added here you an use
sys
,observer
,recon
or OTP debugging tool of choice as if the cowboy processes were using the built in OTP behaviours.Basic HTTP handlers have two new optional callbacks:
Middlewares and sub protocols have the following possible return values:
{ok, Req, Env}
{suspend, Module, Function, Args}
{system, From, Msg, Module, Req, Env, Misc}
{halt, Req, Env}
Notice the new
system
callback and the addition ofEnv
in thehalt
return value.The
system
return value is used to handle system messages. TheModule
used must implement thecowboy_system
callbacks. These are as close as possible tosystem_*
callbacks as possible:And may implement the three optional callbacks (again similar to the
system_*
callbacks):A requirement of supporting the
sys
module is usingproc_lib
. This has the following side effects:crash_report
is sent to the error logger on abnormal exitI will add more to the guide once the API has been finalised/confirmed.