@@ -298,14 +298,20 @@ UserQuery::Ptr UserQueryFactory::newUserQuery(std::string const& aQuery, std::st
298298 }
299299 auto stmt = parser->getSelectStmt ();
300300
301+ // / &&& not entirely sure what the _mutex was protecting _clientToQuery and _idToQuery aren't touched
302+ // / &&& Not sure what internal elements of UserQueryFactory need protection?
303+ // / &&& None of its members look like they need protection.
304+ // / &&& Is there an order of operations to things happening in the database?
305+ std::unique_lock<std::mutex> uLock (_factoryMtx); // &&&
306+
301307 // handle special database/table names
302308 if (_stmtRefersToProcessListTable (stmt, defaultDb)) {
303309 return _makeUserQueryProcessList (stmt, _userQuerySharedResources, userQueryId, resultDb, aQuery,
304- async);
310+ async);
305311 }
306312 if (_stmtRefersQueriesTable (stmt, defaultDb)) {
307313 return _makeUserQueryQueries (stmt, _userQuerySharedResources, userQueryId, resultDb, aQuery,
308- async);
314+ async);
309315 }
310316
311317 // / Determine if a SelectStmt is a simple COUNT(*) query and can be run as an optimized query.
@@ -337,6 +343,7 @@ UserQuery::Ptr UserQueryFactory::newUserQuery(std::string const& aQuery, std::st
337343 auto qs = std::make_shared<qproc::QuerySession>(_userQuerySharedResources->css ,
338344 _userQuerySharedResources->databaseModels , defaultDb,
339345 _userQuerySharedResources->interactiveChunkLimit );
346+ uLock.unlock (); // &&& unlock the mutex before going back to expensive operations.
340347 try {
341348 qs->analyzeQuery (query, stmt);
342349 } catch (...) {
0 commit comments