Skip to content

Commit 5977c1a

Browse files
author
Daniil Fedotov
committed
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
1 parent d704c55 commit 5977c1a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/gm.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,9 +1354,12 @@ find_common(A, B, Common) ->
13541354
find_common(A1, B1, queue:in(Val, Common));
13551355
{{empty, _A}, _} ->
13561356
{Common, B};
1357-
{_, {_, B1}} ->
1357+
%% Drop value from B.
1358+
%% Match value to avoid infinite loop, since {empty, B} = queue:out(B).
1359+
{_, {{value, _}, B1}} ->
13581360
find_common(A, B1, Common);
1359-
{{_, A1}, _} ->
1361+
%% Drop value from A. Empty A should be matched by second close.
1362+
{{{value, _}, A1}, _} ->
13601363
find_common(A1, B, Common)
13611364
end.
13621365

0 commit comments

Comments
 (0)