• Marko Mäkelä's avatar
    MDEV-23996 Race conditions in SHOW ENGINE INNODB MUTEX · 832a6acb
    Marko Mäkelä authored
    The function innodb_show_mutex_status() is the only ultimate caller of
    LatchCounter::iterate() via MutexMonitor::iterate(). Because the call
    is not protected by LatchCounter::m_mutex, any mutex_create() or
    mutex_free() that is invoked concurrently during the execution, bad
    things such as a crash could happen.
    
    The most likely way for this to happen is buffer pool resizing,
    which could cause buf_block_t::mutex (which existed before MDEV-15053)
    to be created or freed. We could also register InnoDB mutexes in
    TrxFactory::init() if trx_pools needs to grow.
    
    The view INFORMATION_SCHEMA.INNODB_MUTEXES is not affected, because it
    only displays information about rw-locks, not mutexes.
    
    This commit intentionally touches also MutexMonitor::iterate()
    and the only code that interfaces with LatchCounter::iterate()
    to make it clearer for future readers that the scattered code
    that is obfuscated by templates belongs together.
    
    This is based on
    mysql/mysql-server@273a93396f49c7e0a8b07b260128d9a990c2b154
    832a6acb
ut0mutex.h 5.32 KB