aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-06-02 12:31:00 +0200
committerLoïc Hoguin <[email protected]>2017-06-02 12:31:00 +0200
commit767da623f1f7329cb0b0d86c3c1876ccf098d60a (patch)
tree7a59761479939b84aad858680d258307430d65bb /src
parentcbf7972f10a5ef96e544df446144bb1a05bcc7cf (diff)
downloadcowboy-767da623f1f7329cb0b0d86c3c1876ccf098d60a.tar.gz
cowboy-767da623f1f7329cb0b0d86c3c1876ccf098d60a.tar.bz2
cowboy-767da623f1f7329cb0b0d86c3c1876ccf098d60a.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http.erl11
1 files changed, 10 insertions, 1 deletions
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.