git: 06c03bcd2f1a - main - databases/mariadb1011-server: Fix Hangs Indefinitely

From: Bernard Spil <brnrd_at_FreeBSD.org>
Date: Sun, 16 Jun 2024 11:33:51 UTC
The branch main has been updated by brnrd:

URL: https://cgit.FreeBSD.org/ports/commit/?id=06c03bcd2f1a0a88cc1a5e8cb1a39a1327bad62d

commit 06c03bcd2f1a0a88cc1a5e8cb1a39a1327bad62d
Author:     Bernard Spil <brnrd@FreeBSD.org>
AuthorDate: 2024-06-16 11:32:13 +0000
Commit:     Bernard Spil <brnrd@FreeBSD.org>
CommitDate: 2024-06-16 11:32:13 +0000

    databases/mariadb1011-server: Fix Hangs Indefinitely
    
    PR:             279362
    Obtained from:  https://jira.mariadb.org/browse/MDEV-34254
---
 databases/mariadb1011-server/Makefile             |  1 +
 databases/mariadb1011-server/files/patch-PR279362 | 85 +++++++++++++++++++++++
 2 files changed, 86 insertions(+)

diff --git a/databases/mariadb1011-server/Makefile b/databases/mariadb1011-server/Makefile
index c05402fe66d9..9859fd79a8b4 100644
--- a/databases/mariadb1011-server/Makefile
+++ b/databases/mariadb1011-server/Makefile
@@ -1,5 +1,6 @@
 PORTNAME?=	mariadb
 PORTVERSION=	10.11.8
+PORTREVISION=	1
 CATEGORIES=	databases
 MASTER_SITES=	https://mirror.nodesdirect.com/${SITESDIR}/ \
 		https://mirror.one.com/${SITESDIR}/ \
diff --git a/databases/mariadb1011-server/files/patch-PR279362 b/databases/mariadb1011-server/files/patch-PR279362
new file mode 100644
index 000000000000..f779ad442e1e
--- /dev/null
+++ b/databases/mariadb1011-server/files/patch-PR279362
@@ -0,0 +1,85 @@
+From 45279cb03d55859423349df7e11caa5ae2b012c5 Mon Sep 17 00:00:00 2001
+From: Dave Gosselin <dave.gosselin@mariadb.com>
+Date: Mon, 13 May 2024 10:36:11 -0400
+Subject: [PATCH] MDEV-34129 mariadb-install-db appears to hang on macOS
+
+A bug in signal_handler thread initialization led to an overcomplicated
+implementation of wait_for_signal_handler_to_end, namely that we could
+fail to initialize the signal handler but mark it as active anyway.
+This meant that we could wait for it to terminate when it didn't exist
+in the first place.
+
+Additionally, let's immediately close down the signal handler loop when
+we decide to break connections--it's the start of process termination
+anyway, and there's no need to wait once we've invoked break_connections.
+--- mysql-test/suite/rpl/r/rpl_shutdown_sighup.result.orig	2024-05-10 21:02:44 UTC
++++ mysql-test/suite/rpl/r/rpl_shutdown_sighup.result
+@@ -41,7 +41,6 @@ connection slave;
+ shutdown;
+ connection server_2;
+ connection slave;
+-include/assert_grep.inc [Ensure warning is issued that signal handler thread is still processing]
+ #
+ # Cleanup
+ connection master;
+ .../suite/rpl/r/rpl_shutdown_sighup.result    |  1 -
+ .../suite/rpl/t/rpl_shutdown_sighup.test      |  7 ---
+ sql/mysqld.cc                                 | 61 ++++++++++---------
+ 3 files changed, 32 insertions(+), 37 deletions(-)
+
+--- mysql-test/suite/rpl/t/rpl_shutdown_sighup.test.orig	2024-05-10 21:02:44 UTC
++++ mysql-test/suite/rpl/t/rpl_shutdown_sighup.test
+@@ -137,13 +137,6 @@ --source include/wait_until_connected_again.inc
+ --enable_reconnect
+ --source include/wait_until_connected_again.inc
+ 
+---let $assert_text= Ensure warning is issued that signal handler thread is still processing
+---let $assert_select= Signal handler thread did not exit in a timely manner.
+---let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.2.err
+---let $assert_count= 1
+---let $assert_only_after = CURRENT_TEST: rpl.rpl_shutdown_sighup
+---source include/assert_grep.inc
+-
+ 
+ --echo #
+ --echo # Cleanup
+diff --git a/sql/mysqld.cc b/sql/mysqld.cc
+index 5ae30282729..68d8a04430f 100644
+--- sql/mysqld.cc.orig
++++ sql/mysqld.cc
+@@ -3205,6 +3205,15 @@ static void start_signal_handler(void)
+   DBUG_VOID_RETURN;
+ }
+ 
++/** Called only from signal_hand function. */
++static void* exit_signal_handler()
++{
++    my_thread_end();
++    signal_thread_in_use= 0;
++    pthread_exit(0);  // Safety
++    return nullptr;  // Avoid compiler warnings
++}
++
+ 
+ /** This threads handles all signals and alarms. */
+ /* ARGSUSED */
+@@ -3265,10 +3274,7 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused)))
+     if (abort_loop)
+     {
+       DBUG_PRINT("quit",("signal_handler: calling my_thread_end()"));
+-      my_thread_end();
+-      signal_thread_in_use= 0;
+-      pthread_exit(0);				// Safety
+-      return 0;                                 // Avoid compiler warnings
++      return exit_signal_handler();
+     }
+     switch (sig) {
+     case SIGTERM:
+@@ -3287,6 +3293,7 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused)))
+         PSI_CALL_delete_current_thread();
+         my_sigset(sig, SIG_IGN);
+         break_connect_loop(); // MIT THREAD has a alarm thread
++        return exit_signal_handler();
+       }
+       break;
+     case SIGHUP: