From 767da623f1f7329cb0b0d86c3c1876ccf098d60a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 2 Jun 2017 12:31:00 +0200 Subject: Fix terminate not being called on connection close in HTTP/1.1 Introduces the new stream_handler_SUITE test suite. More cases will be added later on. --- src/cowboy_http.erl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/cowboy_http.erl') diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index 37ecf8d..a612f20 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -1069,11 +1069,20 @@ error_terminate(StatusCode0, State=#state{ref=Ref, socket=Socket, transport=Tran terminate(State, Reason). -spec terminate(_, _) -> no_return(). -terminate(#state{children=Children}, _Reason) -> +terminate(undefined, Reason) -> + exit({shutdown, Reason}); +terminate(#state{streams=Streams, children=Children}, Reason) -> + terminate_all_streams(Streams, Reason), %% @todo Leave them time to terminate. _ = [exit(Pid, kill) || {Pid, _, _} <- Children], exit(normal). %% @todo We probably don't want to exit normal on errors. +terminate_all_streams([], _) -> + ok; +terminate_all_streams([#stream{id=StreamID, state=StreamState}|Tail], Reason) -> + stream_call_terminate(StreamID, Reason, StreamState), + terminate_all_streams(Tail, Reason). + %% System callbacks. -spec system_continue(_, _, {#state{}, binary()}) -> ok. -- cgit v1.2.3