From 39ab34c250bf416c9d35ffe9c1efde1e423767cc Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Mon, 29 Aug 2022 23:30:17 +0200 Subject: erts: ASSERT DistEntry.state == CONNECTED in erts_do_net_exits --- erts/emulator/beam/dist.c | 1 + 1 file changed, 1 insertion(+) diff --git a/erts/emulator/beam/dist.c b/erts/emulator/beam/dist.c index 0967b94809..ecdbdff624 100644 --- a/erts/emulator/beam/dist.c +++ b/erts/emulator/beam/dist.c @@ -983,6 +983,7 @@ int erts_do_net_exits(DistEntry *dep, Eterm reason) ASSERT(erts_atomic32_read_nob(&dep->qflgs) & ERTS_DE_QFLG_EXIT); } else { + ASSERT(dep->state == ERTS_DE_STATE_CONNECTED); dep->state = ERTS_DE_STATE_EXITING; erts_mtx_lock(&dep->qlock); ASSERT(!(erts_atomic32_read_nob(&dep->qflgs) & ERTS_DE_QFLG_EXIT)); -- cgit v1.2.1 From 84c87ebb899d300f2fd3afcc6d175a23fa2d990b Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Tue, 30 Aug 2022 14:04:44 +0200 Subject: 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 */ -- cgit v1.2.1