simple_bridge
simple_bridge copied to clipboard
timeout in cowboy_simple_bridge:request_body/1
when I use upload_element in nitrogen, there is a error report for simple_bridge as follow:
=INFO REPORT==== 4-Dec-2014::05:17:35 ===
Upload started.
=ERROR REPORT==== 4-Dec-2014::05:17:36 ===
Error in simple_bridge:make/2 - error - {case_clause,{error,timeout}}
[{cowboy_simple_bridge,request_body,1,
[{file,"/home/homeway/erlang/workspace/investors/lib/simple_bridge/src/cowboy_bridge_modules/cowboy_simple_bridge.erl"},
...
I read cowboy document and find this:
body(Req, Opts) -> {ok, Data, Req2} | {more, Data, Req2}
...
It will use a timeout of 15s per chunk.
When I deploy local project, and use local browser, the uploaded file with 2M size would uploaded in 15s, all the things worked well. But when I deploy remote project the error report happened.
Though I change some code in simple_bridge:
%% cowboy_simple_bridge.el
request_body(ReqKey) ->
{RequestCache, Req} = get_key(ReqKey),
{Body, NewReq} = case RequestCache#request_cache.body of
not_loaded ->
%% We start with 2MB here, as headers and form fields will almost
%% certainly be in the first 2mb of a request
- case cowboy_req:body(Req, [{length, 2000000}]) of
+ case cowboy_req:body(Req, [{length, 2000000}, {read_timeout, 120000}]) of
...
It's bug in simple_bridge. my solution can worked well now, but not pretty. Perhaps it's a good idea set the timeout in simple_bridge.config.