From 3fb8535251ea3a72e69f82b178c1691f31ff60dc Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 5 Sep 2020 11:29:14 +0300 Subject: Do not untrap exits if they were already trapped before calling --- lib/concurrent_limiter.ex | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/concurrent_limiter.ex b/lib/concurrent_limiter.ex index 4a367ea..f4d6fbc 100644 --- a/lib/concurrent_limiter.ex +++ b/lib/concurrent_limiter.ex @@ -105,19 +105,22 @@ defmodule ConcurrentLimiter do limiter: name }) - Process.flag(:trap_exit, true) + old_value = Process.flag(:trap_exit, true) try do fun.() after dec(ref, name) - Process.flag(:trap_exit, false) - receive do - {:EXIT, _, reason} -> - Process.exit(self(), reason) - after - 0 -> :noop + unless old_value do + Process.flag(:trap_exit, false) + + receive do + {:EXIT, _, reason} -> + Process.exit(self(), reason) + after + 0 -> :noop + end end end -- cgit v1.2.3