In the ToolsDB config file, we have max_statement_time = 3600 that will kill any query taking longer than 1 hour to complete.
It is still possible to have transactions that last longer than that, if they run multiple queries inside the same transaction and each query takes less than 1 hour. In extreme cases, where a transaction is started and kept open for multiple days, this can cause major issues, as in T409716: [toolsdb] ibdata1 growing on primary.
From a quick search, I don't think there's an easy way to prevent this on the MariaDB side. We could set idle_transaction_timeout to terminate all transactions that are idle for more than a certain amount of time (e.g. 5 minutes), but this would not entirely eliminate the risk. It would still be possible for a tool to start a transaction, then run a query every minute, and it would never reach the 5 minute "idle" threshold.
Another approach could be to write a script that periodically checks for active transactions, and kills them if they've been active for more than a certain amount of time (e.g. 1 hour, to match the current value for max_statement_time).