Skip to content

Commit

Permalink
Discard a payload on a delete attachment request
Browse files Browse the repository at this point in the history
While including a payload within a DELETE request is not forbidden by RFC7231
its presence on a delete attachment request leaves a mochiweb acceptor
in a semi-opened state since mochiweb's using lazy load for the request bodies.
This makes a next immediate request to the same acceptor to hung
until previous request's receive timeout.

This PR adds a step to explicitly "drain" and discard an entity body on a
delete attachment request to prevent that.
  • Loading branch information
eiri committed Aug 26, 2021
1 parent 1b8d4b7 commit 4262714
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/chttpd/src/chttpd_db.erl
Expand Up @@ -857,6 +857,9 @@ db_req(#httpd{path_parts=[_DbName, <<"_local">> | _Rest]}, _Db) ->
db_req(#httpd{path_parts=[_, DocId]}=Req, Db) ->
db_doc_req(Req, Db, DocId);

db_req(#httpd{method='DELETE', path_parts=[_, DocId | FileNameParts]}=Req, Db) ->
chttpd:body(Req),
db_attachment_req(Req, Db, DocId, FileNameParts);
db_req(#httpd{path_parts=[_, DocId | FileNameParts]}=Req, Db) ->
db_attachment_req(Req, Db, DocId, FileNameParts).

Expand Down
15 changes: 15 additions & 0 deletions test/elixir/test/attachments_test.exs
Expand Up @@ -123,6 +123,21 @@ defmodule AttachmentsTest do
assert resp.headers["location"] == nil
end

@tag :with_db
test "delete attachment request with a payload should not block following requests", context do
db_name = context[:db_name]

resp = Couch.put("/#{db_name}/bin_doc", body: @bin_att_doc, query: %{w: 3})
assert resp.status_code in [201, 202]
rev = resp.body["rev"]

resp = Couch.delete("/#{db_name}/bin_doc/foo.txt", body: 'some payload', query: %{w: 3, rev: rev}, ibrowse: [{:max_sessions, 1}, {:max_pipeline_size, 1}])
assert resp.status_code == 200

resp = Couch.get("/", timeout: 1000, ibrowse: [{:max_sessions, 1}, {:max_pipeline_size, 1}])
assert resp.status_code == 200
end

@tag :with_db
test "saves binary", context do
db_name = context[:db_name]
Expand Down

0 comments on commit 4262714

Please sign in to comment.