File 0535-erts-Fix-bug-in-erts_internal-create_dist_channel-3.patch of Package erlang
From 84c87ebb899d300f2fd3afcc6d175a23fa2d990b Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Tue, 30 Aug 2022 14:04:44 +0200
Subject: [PATCH 2/2] erts: Fix bug in erts_internal:create_dist_channel/3
If send to net_kernel fails, do proper cleanup
* Unhook DistEntry from controlling port. It is still in PENDING
state and erts_do_net_exits() assumes DistEntry is/was CONNECTED.
* Set "busy dist entry" on port after success.
---
erts/emulator/beam/dist.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/erts/emulator/beam/dist.c b/erts/emulator/beam/dist.c
index ecdbdff624..dc361930e9 100644
--- a/erts/emulator/beam/dist.c
+++ b/erts/emulator/beam/dist.c
@@ -4940,25 +4940,29 @@ BIF_RETTYPE erts_internal_create_dist_channel_3(BIF_ALIST_3)
: dist_port_command);
ASSERT(dep->send);
- /*
- * Dist-ports do not use the "busy port message queue" functionality, but
- * instead use "busy dist entry" functionality.
- */
- {
- ErlDrvSizeT disable = ERL_DRV_BUSY_MSGQ_DISABLED;
- erl_drv_busy_msgq_limits(ERTS_Port2ErlDrvPort(pp), &disable, NULL);
- }
-
conn_id = dep->connection_id;
set_res = setup_connection_epiloge_rwunlock(BIF_P, dep, BIF_ARG_2, flags,
creation, BIF_P->common.id,
net_kernel);
/* Dec of refc on net_kernel by setup_connection_epiloge_rwunlock() */
net_kernel = NULL;
- if (set_res == 0)
+ if (set_res == 0) {
+ erts_atomic32_read_band_nob(&pp->state, ~ERTS_PORT_SFLG_DISTRIBUTION);
+ erts_prtsd_set(pp, ERTS_PRTSD_DIST_ENTRY, NULL);
+ erts_prtsd_set(pp, ERTS_PRTSD_CONN_ID, NULL);
goto badarg;
+ }
de_locked = 0;
+ /*
+ * Dist-ports do not use the "busy port message queue" functionality,
+ * but instead use "busy dist entry" functionality.
+ */
+ {
+ ErlDrvSizeT disable = ERL_DRV_BUSY_MSGQ_DISABLED;
+ erl_drv_busy_msgq_limits(ERTS_Port2ErlDrvPort(pp), &disable, NULL);
+ }
+
hp = HAlloc(BIF_P, 3 + ERTS_DHANDLE_SIZE);
res = erts_build_dhandle(&hp, &BIF_P->off_heap, dep, conn_id);
res_tag = am_ok; /* Connection up */
--
2.35.3