0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Optionally reset the idle timeout when sending data

A new option reset_idle_timeout_on_send has been added.
When set to 'true', the idle timeout is reset not only
when data is received, but also when data is sent.

This allows sending large responses without having to
worry about timeouts triggering.

The default is currently unchanged but might change in
a future release.

LH: Greatly reworked the implementation so that the
    timeout gets reset on almost all socket writes.
	This essentially completely supersets the original
	work. Tests are mostly the same although I
	refactored a bit to avoid test code duplication.

This commit also changes HTTP/2 behavior a little when
data is received: Cowboy will not attempt to update the
window before running stream handler commands to avoid
sending WINDOW_UPDATE frames twice. Now it has some
small heuristic to ensure they can only be sent once
at most.
This commit is contained in:
Robert J. Macomber 2021-02-08 16:05:05 -08:00 committed by Loïc Hoguin
parent 7400b04b02
commit f74b69c3ed
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
5 changed files with 225 additions and 38 deletions

View file

@ -29,7 +29,8 @@ init_dispatch(_) ->
cowboy_router:compile([{"localhost", [
{"/", hello_h, []},
{"/echo/:key", echo_h, []},
{"/resp_iolist_body", resp_iolist_body_h, []}
{"/resp_iolist_body", resp_iolist_body_h, []},
{"/streamed_result/:n/:interval", streamed_result_h, []}
]}]).
%% Do a prior knowledge handshake (function originally copied from rfc7540_SUITE).
@ -116,6 +117,15 @@ idle_timeout_reset_on_data(Config) ->
cowboy:stop_listener(?FUNCTION_NAME)
end.
idle_timeout_on_send(Config) ->
doc("Ensure the idle timeout is not reset when sending (by default)."),
http_SUITE:do_idle_timeout_on_send(Config, http2).
idle_timeout_reset_on_send(Config) ->
doc("Ensure the reset_idle_timeout_on_send results in the "
"idle timeout resetting when sending ."),
http_SUITE:do_idle_timeout_reset_on_send(Config, http2).
inactivity_timeout(Config) ->
doc("Terminate when the inactivity timeout is reached."),
ProtoOpts = #{