File 0378-erts-release-dirty-runqueue-lock-before-entering-end.patch of Package erlang

From 8368589a9b69b0c8f9d0e9a9c94f51f7afecafa8 Mon Sep 17 00:00:00 2001
From: Maxim Fedorov <dane@whatsapp.com>
Date: Mon, 4 Mar 2019 14:19:05 -0800
Subject: [PATCH] erts: release dirty runqueue lock before entering endless
 loop when BEAM is shutting down

This patch fixes a problem happening when BEAM is shutting down. It is possible for a dirty scheduler to take the lock, and keep it, when the system is shutting down. It may also happen that a normal scheduler decides to schedule some dirty job (example is major garbage collection that results in migrating the process into dirty CPU queue), and hangs trying to take the lock that will never be released.

To fix the problem, either release the lock before entering endless wait loop, or reverse the order in which schedulers are stopped. Either fix works, and, of course, it works even better to apply both.
---
 erts/emulator/beam/erl_process.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/erts/emulator/beam/erl_process.c b/erts/emulator/beam/erl_process.c
index 6779d9f218..5b6885f18e 100644
--- a/erts/emulator/beam/erl_process.c
+++ b/erts/emulator/beam/erl_process.c
@@ -12862,12 +12862,12 @@ void erts_halt(int code)
     if (-1 == erts_smp_atomic32_cmpxchg_acqb(&erts_halt_progress,
 					     erts_no_schedulers,
 					     -1)) {
+        notify_reap_ports_relb();
 #ifdef ERTS_DIRTY_SCHEDULERS
 	ERTS_DIRTY_CPU_RUNQ->halt_in_progress = 1;
 	ERTS_DIRTY_IO_RUNQ->halt_in_progress = 1;
 #endif
 	erts_halt_code = code;
-	notify_reap_ports_relb();
     }
 }
 
-- 
2.16.4

openSUSE Build Service is sponsored by