summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2018-06-22 11:12:40 -0400
committerNick Vatamaniuc <nickva@users.noreply.github.com>2018-06-22 12:06:46 -0400
commit4ad5b326d7de1b53e7da5798ccb33863ba6bbace (patch)
treeb6fb25b761638f5d2056039555ca24b268ff387f
parentfb5dba5b6d73d29271d07d5a3481902deed12399 (diff)
downloadcouchdb-4ad5b326d7de1b53e7da5798ccb33863ba6bbace.tar.gz
A better fix for handling node local 413 responses
During 21.0 testing, the hack to read extra data from the socket to give the client a better chance of detecting a 413 response ended up failing. Either process scheduling or IO scheduling was different enough that the test started failing fairly consistently. Apply a better fix that's more in-line with the intent -- after responding to the client with a 413, read a limited amount of data off the socket (1MB). Limit the maximum time spent doing it to less than 1 second. Issue #1396
-rw-r--r--src/couch/src/couch_httpd.erl7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/couch/src/couch_httpd.erl b/src/couch/src/couch_httpd.erl
index b4f01af9f..1ec709678 100644
--- a/src/couch/src/couch_httpd.erl
+++ b/src/couch/src/couch_httpd.erl
@@ -40,6 +40,8 @@
-define(HANDLER_NAME_IN_MODULE_POS, 6).
+-define(MAX_DRAIN_BYTES, 1048576).
+-define(MAX_DRAIN_TIME_MSEC, 1000).
start_link() ->
start_link(http).
@@ -1181,10 +1183,9 @@ respond_(#httpd{mochi_req = MochiReq}, 413, Headers, Args, Type) ->
% just increases the chances of 413 being detected correctly by the client
% (rather than getting a brutal TCP reset).
erlang:put(mochiweb_request_force_close, true),
- Socket = MochiReq:get(socket),
- mochiweb_socket:recv(Socket, 0, 0),
Result = MochiReq:Type({413, Headers, Args}),
- mochiweb_socket:recv(Socket, 0, 0),
+ Socket = MochiReq:get(socket),
+ mochiweb_socket:recv(Socket, ?MAX_DRAIN_BYTES, ?MAX_DRAIN_TIME_MSEC),
Result;
respond_(#httpd{mochi_req = MochiReq}, Code, Headers, Args, Type) ->
MochiReq:Type({Code, Headers, Args}).