mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Keep the state returned by the tracer callback
It was mistakenly discarded.
This commit is contained in:
parent
32d9d494c7
commit
6cc162583d
2 changed files with 26 additions and 8 deletions
|
@ -144,19 +144,19 @@ tracer_process(StreamID, Req=#{pid := Parent}, Opts=#{tracer_callback := Fun}) -
|
||||||
State = Fun(init, {StreamID, Req, Opts}),
|
State = Fun(init, {StreamID, Req, Opts}),
|
||||||
tracer_loop(Parent, Fun, State).
|
tracer_loop(Parent, Fun, State).
|
||||||
|
|
||||||
tracer_loop(Parent, Fun, State) ->
|
tracer_loop(Parent, Fun, State0) ->
|
||||||
receive
|
receive
|
||||||
Msg when element(1, Msg) =:= trace_ts ->
|
Msg when element(1, Msg) =:= trace_ts ->
|
||||||
Fun(Msg, State),
|
State = Fun(Msg, State0),
|
||||||
tracer_loop(Parent, Fun, State);
|
tracer_loop(Parent, Fun, State);
|
||||||
{'EXIT', Parent, Reason} ->
|
{'EXIT', Parent, Reason} ->
|
||||||
tracer_terminate(Reason, Fun, State);
|
tracer_terminate(Reason, Fun, State0);
|
||||||
{system, From, Request} ->
|
{system, From, Request} ->
|
||||||
sys:handle_system_msg(Request, From, Parent, ?MODULE, [], {Fun, State});
|
sys:handle_system_msg(Request, From, Parent, ?MODULE, [], {Fun, State0});
|
||||||
Msg ->
|
Msg ->
|
||||||
error_logger:error_msg("~p: Tracer process received stray message ~9999p~n",
|
error_logger:error_msg("~p: Tracer process received stray message ~9999p~n",
|
||||||
[?MODULE, Msg]),
|
[?MODULE, Msg]),
|
||||||
tracer_loop(Parent, Fun, State)
|
tracer_loop(Parent, Fun, State0)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
tracer_terminate(Reason, Fun, State) ->
|
tracer_terminate(Reason, Fun, State) ->
|
||||||
|
|
|
@ -98,12 +98,13 @@ do_tracer_callback(Pid) ->
|
||||||
fun
|
fun
|
||||||
(Event, _) when Event =:= init; Event =:= terminate ->
|
(Event, _) when Event =:= init; Event =:= terminate ->
|
||||||
Pid ! Event,
|
Pid ! Event,
|
||||||
undefined;
|
0;
|
||||||
(Event={trace_ts, _, call, {cowboy_req, reply, _}, _}, State) ->
|
(Event={trace_ts, _, call, {cowboy_req, reply, _}, _}, State) ->
|
||||||
Pid ! Event,
|
Pid ! Event,
|
||||||
State;
|
Pid ! {state, State},
|
||||||
|
State + 1;
|
||||||
(_, State) ->
|
(_, State) ->
|
||||||
State
|
State + 1
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% Tests.
|
%% Tests.
|
||||||
|
@ -140,6 +141,23 @@ terminate(Config) ->
|
||||||
error(timeout)
|
error(timeout)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
state(Config) ->
|
||||||
|
doc("Ensure the returned state is used."),
|
||||||
|
Ref = config(ref, Config),
|
||||||
|
Opts = ranch:get_protocol_options(Ref),
|
||||||
|
ranch:set_protocol_options(Ref, Opts#{
|
||||||
|
tracer_callback => do_tracer_callback(self()),
|
||||||
|
tracer_match_specs => [fun(_,_,_) -> true end]
|
||||||
|
}),
|
||||||
|
do_get("/", Config),
|
||||||
|
receive
|
||||||
|
{state, St} ->
|
||||||
|
true = St > 0,
|
||||||
|
ok
|
||||||
|
after 100 ->
|
||||||
|
error(timeout)
|
||||||
|
end.
|
||||||
|
|
||||||
empty(Config) ->
|
empty(Config) ->
|
||||||
doc("Empty match specs unconditionally enable tracing."),
|
doc("Empty match specs unconditionally enable tracing."),
|
||||||
Ref = config(ref, Config),
|
Ref = config(ref, Config),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue