Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix issues with ranch

couchdb has a tendancy to exit from anywhere (old mochiweb design). Make
sure we can really recover from crashes by returning ok when it happen.
We still have some logs due to ranch  but that better than the old
situation.

side note: we are now based on latest stable branch of ranch.
  • Loading branch information...
commit a42866088e17cb48b0b1019b84c740cda48a2da4 1 parent 71a8c4f
@benoitc benoitc authored
View
6 apps/couch_httpd/src/couch_httpd.app.src
@@ -2,13 +2,11 @@
{description, "refuge couchdb HTTP api"},
{vsn, "1.3.0"},
{registered, [
- couch_httpd,
- couch_httpd_config,
couch_httpd_sup
]},
{mod, {couch_httpd_app, []}},
{applications, [kernel, stdlib, lager,
crypto, sasl, public_key,
- ssl, inets, ibrowse, ranch, couch]},
- {included_applications, [oauth, mochiweb]}
+ ssl, inets, ibrowse, oauth, ranch, couch]},
+ {included_applications, [mochiweb]}
]}.
View
2  apps/couch_httpd/src/couch_httpd.erl
@@ -375,7 +375,7 @@ handle_request_int(MochiReq, DefaultFun,
?LOG_ERROR("received invalid Accept-Encoding header", []),
send_error(HttpReq, bad_request);
exit:normal ->
- exit(normal);
+ ok;
exit:snappy_nif_not_loaded ->
ErrorReason = "To access the database or view index, Apache CouchDB"
" must be built with Erlang OTP R13B04 or higher.",
View
20 apps/couch_httpd/src/couch_httpd_protocol.erl
@@ -35,18 +35,17 @@
%% @doc Start a mochiweb process
--spec start_link(pid(), inet:socket(), module(), any()) -> {ok, pid()}.
-start_link(ListenerPid, Socket, Transport, Opts) ->
- Pid = spawn_link(?MODULE, init, [ListenerPid, Socket, Transport, Opts]),
+-spec start_link(any(), inet:socket(), module(), any()) -> {ok, pid()}.
+start_link(Ref, Socket, Transport, Opts) ->
+ Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts]),
{ok, Pid}.
%% @private
--spec init(pid(), inet:socket(), module(), any()) -> ok | none().
-init(ListenerPid, Socket, Transport, Opts) ->
+-spec init(any(), inet:socket(), module(), any()) -> ok | none().
+init(Ref, Socket, Transport, Opts) ->
{loop, HttpLoop} = proplists:lookup(loop, Opts),
- lager:info("listener pid: ~p~n", [ListenerPid]),
- ok = ranch:accept_ack(ListenerPid),
+ ok = ranch:accept_ack(Ref),
loop(#hstate{socket = Socket,
transport = Transport,
loop = HttpLoop}).
@@ -91,7 +90,7 @@ headers(#hstate{transport=Transport, socket=Socket, loop=Loop}=State, Request,
{Protocol, _, http_eoh}
when Protocol == http orelse Protocol == ssl ->
Req = new_request(State, Request, Headers),
- call_body(Loop, Req),
+ catch(call_body(Loop, Req)),
?MODULE:after_response(Loop, Req);
{Protocol, _, {http_header, _, Name, _, Value}}
when Protocol == http orelse Protocol == ssl ->
@@ -148,8 +147,9 @@ after_response(Body, Req) ->
case Req:should_close() of
true ->
+ lager:info("fuck you", []),
mochiweb_socket:close(Socket),
- exit(normal);
+ ok;
false ->
Req:cleanup(),
erlang:garbage_collect(),
@@ -170,4 +170,4 @@ mochiweb_socket(#hstate{transport=Transport, socket=Socket}) ->
terminate(#hstate{transport=Transport, socket=Socket}) ->
Transport:close(Socket),
- exit(normal).
+ ok.
Please sign in to comment.
Something went wrong with that request. Please try again.