From bfee20e61e9f6f4ad2e2d39d68c9c94910c67bac Mon Sep 17 00:00:00 2001 From: Steve Strong Date: Wed, 13 Mar 2019 11:36:04 +0000 Subject: Bind erlang:get_stacktrace prior to making other calls If we bind too late there might be an exception triggered in the terminate function and we will not get the correct stacktrace as a result. --- src/cowboy_loop.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/cowboy_loop.erl') diff --git a/src/cowboy_loop.erl b/src/cowboy_loop.erl index 2e5ecdb..603c939 100644 --- a/src/cowboy_loop.erl +++ b/src/cowboy_loop.erl @@ -82,8 +82,9 @@ call(Req0, Env, Handler, HandlerState0, Message) -> {stop, Req, HandlerState} -> terminate(Req, Env, Handler, HandlerState, stop) catch Class:Reason -> + StackTrace = erlang:get_stacktrace(), cowboy_handler:terminate({crash, Class, Reason}, Req0, HandlerState0, Handler), - erlang:raise(Class, Reason, erlang:get_stacktrace()) + erlang:raise(Class, Reason, StackTrace) end. suspend(Req, Env, Handler, HandlerState) -> -- cgit v1.2.3