Skip to content

Commit

Permalink
fix apache#745: avoid race condition in mp-parser chunk handling (by @…
Browse files Browse the repository at this point in the history
  • Loading branch information
janl committed Feb 20, 2018
1 parent 302bd8b commit d00d93d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/couch/src/couch_httpd_multipart.erl
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ maybe_send_data({Ref, Chunks, Offset, Counters, Waiting}) ->
end, Waiting),

% check if we can drop a chunk from the head of the list
case Counters of
SmallestIndex = case Counters of
[] ->
SmallestIndex = 0;
0;
_ ->
SmallestIndex = lists:min(element(2, lists:unzip(Counters)))
lists:min([C || {_WPid, {_WRef, C}} <- Counters])
end,
Size = length(Counters),
N = num_mp_writers(),
Expand All @@ -149,7 +149,7 @@ maybe_send_data({Ref, Chunks, Offset, Counters, Waiting}) ->
end,

% we should wait for a writer if no one has written the last chunk
LargestIndex = lists:max([0|element(2, lists:unzip(Counters))]),
LargestIndex = lists:max([0] ++ [C || {_WPid, {_WRef, C}} <- Counters]),
if LargestIndex >= (Offset + length(Chunks)) ->
% someone has written all possible chunks, keep moving
{Ref, NewChunks, NewOffset, Counters, NewWaiting};
Expand Down

0 comments on commit d00d93d

Please sign in to comment.