From 38968760804c522e0aa1b82f02834f28d6d24633 Mon Sep 17 00:00:00 2001 From: Rickard Green Date: Tue, 4 Apr 2023 20:00:57 +0200 Subject: [PATCH] [erts] Fix auto connect from net_kernel This bug was harmless. Prior to ff7daaca438743cc14b79ed73c2fd6a1e7b46307 (on master prior to OTP-26.0-rc3) net_kernel never triggered auto connect itself. After that commit, when net_kernel triggered auto connect, the runtime system would try-lock the main-lock on net_kernel while executing net_kernel when sending a message to net_kernel. An assertion would trigger, but in the optimized runtime this would just cause the try-lock to fail and the message to unnecessarily to be placed in a heap-fragment. --- erts/emulator/beam/dist.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/erts/emulator/beam/dist.c b/erts/emulator/beam/dist.c index daf07e5fa79b..ca6aa40185e9 100644 --- a/erts/emulator/beam/dist.c +++ b/erts/emulator/beam/dist.c @@ -5589,6 +5589,9 @@ int erts_auto_connect(DistEntry* dep, Process *proc, ErtsProcLocks proc_locks) return 0; } + if (proc == net_kernel) + nk_locks |= ERTS_PROC_LOCK_MAIN; + /* * Send {auto_connect, Node, DHandle} to net_kernel */ @@ -5599,6 +5602,10 @@ int erts_auto_connect(DistEntry* dep, Process *proc, ErtsProcLocks proc_locks) msg = TUPLE3(hp, am_auto_connect, dep->sysname, dhandle); ERL_MESSAGE_TOKEN(mp) = am_undefined; erts_queue_proc_message(proc, net_kernel, nk_locks, mp, msg); + + if (proc == net_kernel) + nk_locks &= ~ERTS_PROC_LOCK_MAIN; + erts_proc_unlock(net_kernel, nk_locks); }