From 48eefebff2d0412bf6fe8a53182ef88a443b293f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 5 Jun 2023 10:52:07 +0200 Subject: Fix crash when TLS connection closes very early And ensure that we don't infinite loop when retries are enabled, by decrementing the retry count instead of using a new one. Also check for ssl:negotiated_protocol {error,closed} which was possible but was not documented in OTP before this change. Thanks @voluntas for the help. --- test/gun_test.erl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/gun_test.erl') diff --git a/test/gun_test.erl b/test/gun_test.erl index 5142898..18fcfbf 100644 --- a/test/gun_test.erl +++ b/test/gun_test.erl @@ -33,7 +33,7 @@ init_origin(Transport) -> init_origin(Transport, http). init_origin(Transport, Protocol) -> - init_origin(Transport, Protocol, fun loop_origin/3). + init_origin(Transport, Protocol, fun loop_origin/4). init_origin(Transport, Protocol, Fun) -> Pid = spawn_link(?MODULE, init_origin, [self(), Transport, Protocol, Fun]), @@ -55,7 +55,7 @@ init_origin(Parent, Transport, Protocol, Fun) _ -> ok end, Parent ! {self(), handshake_completed}, - Fun(Parent, ClientSocket, gen_tcp); + Fun(Parent, ListenSocket, ClientSocket, gen_tcp); init_origin(Parent, tls, Protocol, Fun) -> Opts0 = ct_helper:get_certs_from_ets(), Opts1 = case Protocol of @@ -77,7 +77,7 @@ init_origin(Parent, tls, Protocol, Fun) -> ok end, Parent ! {self(), handshake_completed}, - Fun(Parent, ClientSocket, ssl). + Fun(Parent, ListenSocket, ClientSocket, ssl). http2_handshake(Socket, Transport) -> %% Send a valid preface. @@ -96,11 +96,11 @@ http2_handshake(Socket, Transport) -> {ok, <<0:24, 4:8, 1:8, 0:32>>} = Transport:recv(Socket, 9, 5000), ok. -loop_origin(Parent, ClientSocket, ClientTransport) -> +loop_origin(Parent, ListenSocket, ClientSocket, ClientTransport) -> case ClientTransport:recv(ClientSocket, 0, 5000) of {ok, Data} -> Parent ! {self(), Data}, - loop_origin(Parent, ClientSocket, ClientTransport); + loop_origin(Parent, ListenSocket, ClientSocket, ClientTransport); {error, closed} -> ok end. -- cgit v1.2.3