From 440f9d129b5a728a0ef6a900f5cc273782f04eec Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Thu, 28 Nov 2019 14:46:46 +0100 Subject: [PATCH] Handle undefined fetcher in fold loop exception Prior to this commit, fold loop may crash if there is an exception in message handler callback when processing the last batch (i.e. when there is no running fetcher for the next batch), kill_fetcher function may crash on 'undefined' clause --- src/brod_utils.erl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/brod_utils.erl b/src/brod_utils.erl index e9b3f83d..78508f83 100644 --- a/src/brod_utils.erl +++ b/src/brod_utils.erl @@ -612,6 +612,7 @@ do_acc(Spawn, Fetcher, Offset, Acc, Fun, [Msg | Rest], End, Count) -> erlang:raise(C, E, Stack) end. +kill_fetcher(undefined) -> ok; kill_fetcher({Pid, Mref}) -> exit(Pid, kill), receive