From 120bf6a46ef55f3b9eebb4b5e49b0663e4fbfc05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D1=80=D0=BE?= =?UTF-8?q?=D1=85=D0=BE=D1=80=D0=BE=D0=B2?= Date: Sat, 27 Oct 2018 20:35:44 +0200 Subject: [PATCH] Garbage-collect self before making final decision about termination --- src/mtp_handler.erl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mtp_handler.erl b/src/mtp_handler.erl index d72b077..db56415 100644 --- a/src/mtp_handler.erl +++ b/src/mtp_handler.erl @@ -320,7 +320,7 @@ check_queue_overflow(#state{last_queue_check = LastCheck} = S) -> true -> {noreply, S}; false -> - case do_check_queue_overflow() of + case do_check_queue_overflow(true) of ok -> {noreply, S#state{last_queue_check = NowMs}}; overflow -> @@ -328,7 +328,7 @@ check_queue_overflow(#state{last_queue_check = LastCheck} = S) -> end end. -do_check_queue_overflow() -> +do_check_queue_overflow(Gc) -> [{_, QLen}, {_, Mem}, {_, Bin}] = erlang:process_info(self(), [message_queue_len, memory, binary]), %% BinSum = sum_binary(Bin), @@ -339,6 +339,9 @@ do_check_queue_overflow() -> RefcBinSize = sum_binary(Bin), TotalMem = Mem + RefcBinSize, case TotalMem > ?QUEUE_CHECK_MAX_MEM of + true when Gc-> + erlang:garbage_collect(self()), + do_check_queue_overflow(false); true -> lager:warning( "Process too large queue_len=~w, memory=~w, binary_sum=~w, binary=~p",