File bind-ensure-file-descriptors-0-2-are-in-use-before-using-.patch of Package bind.40691
From 5cfdbeba72092e3e5f48f4b071084585efc5219f Mon Sep 17 00:00:00 2001
From: Thomas Abraham <tabraham@suse.com>
Date: Mon, 30 Jun 2025 14:03:56 -0400
Subject: [PATCH] ensure file descriptors 0-2 are in use before using libuv
libuv expects file descriptors <= STDERR_FILENO are in use. otherwise,
it may abort when closing a file descriptor it opened.
See https://github.com/libuv/libuv/pull/4559
Closes #5226
---
diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c
index 6a66bd5fdb..e1c2052207 100644
--- a/lib/isc/netmgr/netmgr.c
+++ b/lib/isc/netmgr/netmgr.c
@@ -189,6 +189,23 @@ isc_nm_start(isc_mem_t *mctx, uint32_t workers) {
mgr->workers = isc_mem_get(mctx,
mgr->nworkers * sizeof(isc__networker_t));
+
+ /*
+ * Ensure the first 3 file descriptors are open
+ * otherwise, libuv may use one and trigger abort
+ * when closing it.
+ *
+ * See https://github.com/libuv/libuv/pull/4559
+ */
+ do {
+ int fd = open("/dev/null", O_RDWR, 0);
+ RUNTIME_CHECK(fd >= 0);
+ if (fd > STDERR_FILENO) {
+ close (fd);
+ break;
+ }
+ } while (true);
+
for (int i = 0; i < mgr->nworkers; i++) {
isc__networker_t *worker = &mgr->workers[i];
int r;