Skip to content
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

[#1551] Handle external exits of processes #1514

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hubertlepicki
Copy link

@hubertlepicki hubertlepicki commented Apr 23, 2021

Relates to #1511

Adds handler to capture external exits of processes, and tests to verify
this is indeed happening.

On my Elixir/Phoenix project, where I add such line in a controller to kill the process:

Process.exit(self(), :kill) 

Without this change, no exception or error is reported to the logger.

With these changes I see the error line as I'd expect:

14:07:06.341 [error] Ranch listener UI.Endpoint.HTTP, connection process #PID<0.14777.0>, stream 9 had its request process #PID<0.14896.0> exit with reason :killed

There is at least one one problem: I don't know how to silence crash reports in this case. When I run the tests, I can see the crash reports I added, but I would like to silence them in tests. ct_helper:ignore() doesn't seem to cut it the way I use it, which is probably wrong. I see on the console:

Testing ninenines.cowboy.metrics_SUITE: Starting test, 96 test cases

=ERROR REPORT==== 23-Apr-2021::11:22:09 ===
Ranch listener http, connection process <0.266.0>, stream 1 had its
request process <0.275.0> exit with reason external_exit

which we probably want to silence but I'm not sure how, so a suggestion how and a general review of my code would be very much appreciated. Unfortunately I don't write Erlang daily so I appreciate feedback.

Adds handler to capture external exits of processes, and tests to verify
this is indeed happening.

Problem: I don't know how to silence crash reports in this case. When I
run the tests, I can see the crash reports I added, but I would like to
silence them in tests. ct_helper:ignore() doesn't seem to cut it the way
I use it, which is probably wrong. I see on the console:

Testing ninenines.cowboy.metrics_SUITE: Starting test, 96 test cases

=ERROR REPORT==== 23-Apr-2021::11:22:09 ===
Ranch listener http, connection process <0.266.0>, stream 1 had its
request process <0.275.0> exit with reason external_exit

which we probably want to silence but I'm not sure how. Help?
@hubertlepicki hubertlepicki changed the title [1551] Handle external exits of processes [#1551] Handle external exits of processes Apr 23, 2021
Copy link
Member

@essen essen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There currently is no mechanism to ignore exit messages. Feel free to send a PR for ct_helper or to just leave the exit message for now. If a PR then please don't spend too much time before proposing a solution, I haven't done any thinking about this yet.

@@ -154,6 +154,22 @@ info(StreamID, Exit={'EXIT', Pid, {Reason, Stacktrace}}, State=#state{ref=Ref, p
do_info(StreamID, Exit, [
{error_response, 500, #{<<"content-length">> => <<"0">>}, <<>>}
|Commands], State);
info(StreamID, Exit={'EXIT', Pid, Reason}, State=#state{ref=Ref, pid=Pid}) ->
Commands0 = [{internal_error, Exit, 'Stream process crashed.'}],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use exited rather than crashed.

end,
do_info(StreamID, Exit, [
{error_response, 500, #{<<"content-length">> => <<"0">>}, <<>>}
|Commands], State);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably extract all this into a separate function, with slightly different behavior depending on the presence of a stacktrace (use undefined for the exit case).

exit(internal_exit);
init(_, external_exit) ->
ct_helper:ignore(?MODULE, init, 2),
exit(self(), external_exit).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ignore function is about crashes not exits. This handler is about crashes as well. I don't think this belongs here. A better place for this test would be in stream_handler_SUITE similar to this test https://github.com/ninenines/cowboy/blob/master/test/stream_handler_SUITE.erl#L341-L362 (just get the pid and exit the process immediately, the test shouldn't be that long). It's OK to only test exit/2 in this case.

ref := _,
pid := From,
streamid := 1,
reason := {internal_error, {'EXIT', _Pid, external_exit}, 'Stream process crashed.'},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, checking this still seems valuable. So I would leave this test. I would just do the exit from the test case instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright makes sense. On it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants