File 0886-erts-Fix-windows-spin-bug-when-stdio-is-closed.patch of Package erlang

From 02378c6fb46b31e92c69ffe86e4dc3d74accb7b7 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Wed, 1 Apr 2020 09:53:49 +0000
Subject: [PATCH 3/3] erts: Fix windows spin bug when stdio is closed

Example symptom:
os:cmd("escript something") would cause 100% cpu and even increasing
memory consumption.

Problem:
threaded_reader() keeps calling ReadFile and getting 0 bytes read
which are even sent as {Port, {data, <<>>}} messages from port.

Fix:
Exit threaded_reader() if 0 bytes is read. This was already done but only
if CRLF->LF conversion was disabled, which I don't understand why. Could be
someone was "unlucky" thinking "the CRLF conversion may decrease
bytesTransferred down to zero", which it cannot.
---
 erts/emulator/sys/win32/sys.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/erts/emulator/sys/win32/sys.c b/erts/emulator/sys/win32/sys.c
index 957ade51c3..64d61b4d19 100644
--- a/erts/emulator/sys/win32/sys.c
+++ b/erts/emulator/sys/win32/sys.c
@@ -1697,7 +1697,7 @@ create_child_process
 	    erts_free(ERTS_ALC_T_TMP, qte);
 	}	    
 	    
-	DEBUGF((stderr,"Creating child process: %S, createFlags = %d\n", newcmdline, createFlags));
+	DEBUGF(("Creating child process: %S, createFlags = %d\n", newcmdline, createFlags));
 	ok = CreateProcessW((wchar_t *) appname,
 			    (wchar_t *) newcmdline,
 			    NULL,
@@ -1995,7 +1995,7 @@ threaded_reader(LPVOID param)
 	    aio->bytesTransferred = n;
 	}
 	SetEvent(aio->ov.hEvent);
-	if ((aio->flags & DF_XLAT_CR) == 0 && aio->bytesTransferred == 0) {
+	if (aio->bytesTransferred == 0) {
 	    break;
 	}
 	if (aio->pendingError != NO_ERROR) {
-- 
2.16.4

openSUSE Build Service is sponsored by