Skip to content

Commit

Permalink
Merge pull request #18 from erlcloud/otp-21-compat
Browse files Browse the repository at this point in the history
Support OTP 21 stack traces, Add OTP 21 to test, cleanup
  • Loading branch information
Evgeny Bob authored Oct 12, 2018
2 parents 3ca9bdc + 697460b commit 827e6cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ otp_release:
- 17.5
- 18.3
- 19.3.6
- 20.0.5
- 20.3.8
- 21.1
script: "make test"
17 changes: 12 additions & 5 deletions src/lhttpc_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
-define(CONNECTION_HDR(HDRS, DEFAULT),
string:to_lower(lhttpc_lib:header_value("connection", HDRS, DEFAULT))).

-ifdef(OTP_RELEASE). %% this implies 21 or higher
-define(EXCEPTION(Class, Reason, Stacktrace), Class:Reason:Stacktrace).
-define(GET_STACK(Stacktrace), Stacktrace).
-else.
-define(EXCEPTION(Class, Reason, _), Class:Reason).
-define(GET_STACK(_), erlang:get_stacktrace()).
-endif.

-record(client_state, {
host :: string(),
port = 80 :: port_num(),
Expand Down Expand Up @@ -96,9 +104,8 @@ request(From, Host, Port, Ssl, Path, Method, Hdrs, Body, Options) ->
{response, self(), {error, Reason}};
error:closed ->
{response, self(), {error, connection_closed}};
Class:Reason when Class == error; Class == exit ->
Stack = erlang:get_stacktrace(),
{response, self(), {error, {Reason, Stack}}}
?EXCEPTION(Class, Reason, Stacktrace) when Class == error; Class == exit ->
{response, self(), {error, {Reason, ?GET_STACK(Stacktrace)}}}
end,
case Result of
{response, _, {ok, {no_return, _}}} -> ok;
Expand Down Expand Up @@ -223,9 +230,9 @@ send_request(#client_state{socket = undefined} = State) ->
catch
exit:{{{badmatch, {error, {asn1, _}}}, _}, _} ->
throw(ssl_decode_error);
Type:Error ->
?EXCEPTION(Type, Error, Stacktrace) ->
error_logger:error_msg("Socket connection error: ~p ~p, ~p",
[Type, Error, erlang:get_stacktrace()])
[Type, Error, ?GET_STACK(Stacktrace)])
end;
send_request(#client_state{proxy = #lhttpc_url{}, proxy_setup = false} = State) ->
% use a proxy.
Expand Down
8 changes: 0 additions & 8 deletions src/lhttpc_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,6 @@ client_done(Pool, Host, Port, Ssl, Socket) ->
init(Options) ->
process_flag(trap_exit, true),
process_flag(priority, high),
case lists:member({seed,1}, ssl:module_info(exports)) of
true ->
% Make sure that the ssl random number generator is seeded
% This was new in R13 (ssl-3.10.1 in R13B vs. ssl-3.10.0 in R12B-5)
apply(ssl, seed, [crypto:rand_bytes(255)]);
false ->
ok
end,
Timeout = proplists:get_value(connection_timeout, Options),
Size = proplists:get_value(pool_size, Options),
{ok, #httpc_man{timeout = Timeout, max_pool_size = Size}}.
Expand Down

0 comments on commit 827e6cb

Please sign in to comment.