Skip to content

Commit

Permalink
MB-37100: Stop timeout timer before sending first response
Browse files Browse the repository at this point in the history
view-engine uses same tcp connection to perform multiple
gather queries from other nodes. When it receives a request,
node will start the timer and after connection_timeout
milliseconds it will force close the connection.
In that case if there is any long running query
in receiving end will try to read from closed socket.
This patch will clear the timer before the successful
streaming of first response.

Change-Id: Ie0191484f718c1b34c0a5c9ee17bad8e5a174486
Reviewed-on: http://review.couchbase.org/118681
Reviewed-by: Suraj Naik <suraj.naik@couchbase.com>
Tested-by: Matt Carabine <matt.carabine@couchbase.com>
Tested-by: <ankit.prabhu@couchbase.com>
  • Loading branch information
AnkitPrabhu committed Dec 2, 2019
1 parent e9a83c2 commit a1f359d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/couch_index_merger/src/couch_httpd_view_merger.erl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ http_sender({debug_info, From, Info}, SAcc) ->
{ok, SAcc#sender_acc{debug_info_acc = DebugInfoAcc2}};

http_sender(start, #sender_acc{req = Req} = SAcc) ->
maybe_stop_timer(),
#httpd{mochi_req = MReq} = Req,
ok = mochiweb_socket:setopts(MReq:get(socket), [{nodelay, true}]),
{ok, Resp} = couch_httpd:start_json_response(Req, 200, []),
Expand All @@ -129,13 +130,7 @@ http_sender(start, #sender_acc{req = Req} = SAcc) ->
http_sender({start, RowCount}, #sender_acc{req = Req} = SAcc) ->
% The remote node is ready to start streaming the response
% Call off the hit
case get(tref) of
nil ->
ok;
TRef ->
timer:cancel(TRef),
erase(tref)
end,
maybe_stop_timer(),
#httpd{mochi_req = MReq} = Req,
ok = mochiweb_socket:setopts(MReq:get(socket), [{nodelay, true}]),
{ok, Resp} = couch_httpd:start_json_response(Req, 200, []),
Expand Down Expand Up @@ -260,3 +255,12 @@ log_bytes(Req, Size) ->
catch
_:_ -> ok
end.

maybe_stop_timer() ->
case get(tref) of
undefined ->
ok;
TRef ->
timer:cancel(TRef),
erase(tref)
end.

0 comments on commit a1f359d

Please sign in to comment.