summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Fedotov <dfedotov@pivotal.io>2017-11-22 17:27:48 +0000
committerDaniil Fedotov <dfedotov@pivotal.io>2017-11-23 12:03:02 +0000
commit5977c1a0ba6bded40b4a20a5317c4f62489743cf (patch)
tree1a3ba80f928e5b473b2ade8938e519d48f445730 /src
parentd704c5501b423244bf63e458f1192518915150bb (diff)
downloadrabbitmq-server-git-5977c1a0ba6bded40b4a20a5317c4f62489743cf.tar.gz
Avoid infinite loop when dropping gm queue entries.
Since `out` operation on empty queue is idempotent `queue:out(B) = {empty, B}`, there can be a potential infinite loop when dropping messages. Matching that there is a value to drop. Empty A queue should be handled by second clause. Related to #779
Diffstat (limited to 'src')
-rw-r--r--src/gm.erl7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/gm.erl b/src/gm.erl
index cf3e217010..d6005fe554 100644
--- a/src/gm.erl
+++ b/src/gm.erl
@@ -1354,9 +1354,12 @@ find_common(A, B, Common) ->
find_common(A1, B1, queue:in(Val, Common));
{{empty, _A}, _} ->
{Common, B};
- {_, {_, B1}} ->
+ %% Drop value from B.
+ %% Match value to avoid infinite loop, since {empty, B} = queue:out(B).
+ {_, {{value, _}, B1}} ->
find_common(A, B1, Common);
- {{_, A1}, _} ->
+ %% Drop value from A. Empty A should be matched by second close.
+ {{{value, _}, A1}, _} ->
find_common(A1, B, Common)
end.