Skip to content

Commit

Permalink
core: fix comet connection, set cowboy request timeout to 60 secs (in…
Browse files Browse the repository at this point in the history
…stead of default 5).
  • Loading branch information
mworrell committed Mar 7, 2017
1 parent f88633e commit ad0ec75
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
9 changes: 6 additions & 3 deletions modules/mod_base/controllers/controller_comet.erl
@@ -1,8 +1,8 @@
%% @author Marc Worrell <marc@worrell.nl>
%% @copyright 2009 Marc Worrell
%% @copyright 2009-2017 Marc Worrell
%% @doc Handles comet long polls from the user agent

%% Copyright 2009 Marc Worrell
%% Copyright 2009-2017 Marc Worrell
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,7 +50,10 @@ allowed_methods(Context) ->
{[<<"POST">>], Context}.

content_types_provided(Context) ->
{[<<"text/x-ubf">>], Context}.
{[
{<<"text/x-ubf">>, process_post},
{<<"text/plain">>, process_post}
], Context}.

%% @doc Collect all data to be pushed back to the user agent
process_post(Context) ->
Expand Down
8 changes: 4 additions & 4 deletions src/support/z_transport_comet.erl
@@ -1,8 +1,8 @@
%% @author Marc Worrell <marc@worrell.nl>
%% @copyright 2015 Marc Worrell
%% @copyright 2015-2017 Marc Worrell
%% @doc Handles comet long polls from the user agent

%% Copyright 2015 Marc Worrell
%% Copyright 2015-2017 Marc Worrell
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
Expand All @@ -26,11 +26,11 @@

-include_lib("zotonic.hrl").

%% Timeout for comet flush when there is no data, webmachine 0.x had a timeout of 60 seconds, so leave after 55
%% Timeout for comet flush when there is no data, we use a cowboy request_timeout of 60 seconds, so leave after 55
-define(COMET_FLUSH_EMPTY, 55000).

%% Timeout for comet flush when there is data, allow for 100 msec more to gather extra data before flushing
%% This must be higher than SIDEJOB_TIMEOUT in controlelr_postback.erl
%% This must be higher than SIDEJOB_TIMEOUT in controller_postback.erl
-define(COMET_FLUSH_DATA, 100).


Expand Down
2 changes: 2 additions & 0 deletions src/zotonic.erl
Expand Up @@ -39,6 +39,7 @@
-include_lib("zotonic.hrl").

-define(MIN_OTP_VERSION, "18").
-define(HTTP_REQUEST_TIMEOUT, 60000).

-spec ensure_started(atom()) -> ok | {error, term()}.
ensure_started(App) ->
Expand Down Expand Up @@ -146,6 +147,7 @@ start_http_listeners() ->
lager:info("Web server listening on IPv4 ~p:~p, SSL ~p::~p", [WebIp, WebPort, WebIp, SSLPort]),
CowboyOpts = #{
middlewares => [ cowmachine_proxy, z_sites_dispatcher, z_cowmachine_middleware ],
request_timeout => ?HTTP_REQUEST_TIMEOUT,
env => #{}
},
WebIP4Opt = case WebIp of
Expand Down

0 comments on commit ad0ec75

Please sign in to comment.