File 0634-erts-Fix-bug-in-erts_io_notify_port_task_executed.patch of Package erlang

From b8d4d604048becbfdcaab32e359176fab5f67cc4 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Thu, 12 Jan 2023 14:40:14 +0100
Subject: [PATCH] erts: Fix bug in erts_io_notify_port_task_executed

Seen symptom:

Failed assert
DEBUG_PRINT_FD("executed ready_input", state);
ASSERT(!(state->active_events & ERTS_POLL_EV_IN));

with state->type == ERTS_EV_TYPE_NIF
that is, the fd already closed and then reused by a NIF.
---
 erts/emulator/sys/common/erl_check_io.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/erts/emulator/sys/common/erl_check_io.c b/erts/emulator/sys/common/erl_check_io.c
index 964f2df27e..7cd4948c83 100644
--- a/erts/emulator/sys/common/erl_check_io.c
+++ b/erts/emulator/sys/common/erl_check_io.c
@@ -486,14 +486,16 @@ erts_io_notify_port_task_executed(ErtsPortTaskType type,
 
     active_events = state->active_events;
 
-    if (!(state->flags & ERTS_EV_FLAG_IN_SCHEDULER) || type == ERTS_PORT_TASK_OUTPUT) {
+    if (state->type == ERTS_EV_TYPE_DRV_SEL) {
         switch (type) {
         case ERTS_PORT_TASK_INPUT:
 
             DEBUG_PRINT_FD("executed ready_input", state);
 
-            ASSERT(!(state->active_events & ERTS_POLL_EV_IN));
-            if (state->events & ERTS_POLL_EV_IN) {
+            if (!(state->flags & ERTS_EV_FLAG_IN_SCHEDULER)
+                && !(active_events & ERTS_POLL_EV_IN)
+                && (state->events & ERTS_POLL_EV_IN)) {
+
                 active_events |= ERTS_POLL_EV_IN;
                 if (state->count > 10 && ERTS_POLL_USE_SCHEDULER_POLLING) {
                     if (!(state->flags & ERTS_EV_FLAG_SCHEDULER))
@@ -511,8 +513,9 @@ erts_io_notify_port_task_executed(ErtsPortTaskType type,
 
             DEBUG_PRINT_FD("executed ready_output", state);
 
-            ASSERT(!(state->active_events & ERTS_POLL_EV_OUT));
-            if (state->events & ERTS_POLL_EV_OUT) {
+            if (!(active_events & ERTS_POLL_EV_OUT)
+                && (state->events & ERTS_POLL_EV_OUT)) {
+
                 active_events |= ERTS_POLL_EV_OUT;
                 if (state->flags & ERTS_EV_FLAG_IN_SCHEDULER && active_events & ERTS_POLL_EV_IN)
                     new_events = ERTS_POLL_EV_OUT;
@@ -525,7 +528,8 @@ erts_io_notify_port_task_executed(ErtsPortTaskType type,
             break;
         }
 
-        if (state->active_events != active_events && new_events) {
+        if (state->active_events != active_events) {
+            ASSERT(new_events);
             state->active_events = active_events;
             new_events = erts_io_control(state, op, new_events);
         }
-- 
2.35.3

openSUSE Build Service is sponsored by