From 7e297250503e290a62ed947eb556177b13887e45 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Mon, 16 Apr 2018 13:25:33 +0300 Subject: [PATCH] MXS-1805 Force all maxadmin connections to main thread If maxadmin connections are handled by different workers, then there may be a deadlock if some maxadmin command requires communication with all workers. Namely, in that case a message will be sent to all other workers but the current one, but that message will not be handled if that other worker at that point sits in the debugcmd_lock spinlock in debugcmd.c:execute_cmd(). We can prevent that deadlock from happening simply by ensuring that all maxadmin connections are handled by one thread. --- server/core/dcb.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/core/dcb.cc b/server/core/dcb.cc index 2e9133bed..9d043124c 100644 --- a/server/core/dcb.cc +++ b/server/core/dcb.cc @@ -3419,6 +3419,18 @@ int poll_add_dcb(DCB *dcb) new_state = DCB_STATE_LISTENING; worker_id = MXS_WORKER_ALL; } + else if (dcb->dcb_role == DCB_ROLE_CLIENT_HANDLER && + (strcasecmp(dcb->service->routerModule, "cli") == 0)) + { + // If the DCB refers to an accepted maxadmin socket, we force it + // to the main thread. That's done in order to prevent a deadlock + // that may happen if there are multiple concurrent maxadmin calls, + // handled by different worker threads. + // See: https://jira.mariadb.org/browse/MXS-1805 + new_state = DCB_STATE_POLLING; + dcb->poll.thread.id = 0; + worker_id = dcb->poll.thread.id; + } else { ss_dassert(dcb->dcb_role == DCB_ROLE_CLIENT_HANDLER ||