• Jon Olav Hauglid's avatar
    Bug #51160 Deadlock around SET GLOBAL EVENT_SCHEDULER = ON|OFF · c7c1f219
    Jon Olav Hauglid authored
    This deadlock could occour betweeen one connection executing
    SET GLOBAL EVENT_SCHEDULER= ON and another executing SET GLOBAL
    EVENT_SCHEDULER= OFF. The bug was introduced by WL#4738.
    
    The first connection would hold LOCK_event_metadata (protecting
    the global variable) while trying to lock LOCK_global_system_variables
    starting the event scheduler thread (in THD:init()).
    
    The second connection would hold LOCK_global_system_variables
    while trying to get LOCK_event_scheduler after stopping the event
    scheduler inside event_scheduler_update().
    
    This patch fixes the problem by not using LOCK_event_metadata to
    protect the event_scheduler variable. It is still protected using
    LOCK_global_system_variables. This fixes the deadlock as it removes 
    one of the two mutexes used to produce it.
    
    However, this patch opens up the possibility that the event_scheduler
    variable and the real event_scheduler state can become out of sync
    (e.g. variable = OFF, but scheduler running). But this can only
    happen under very unlikely conditions - two concurrent SET GLOBAL
    statments, with one thread interrupted at the exact wrong moment.
    This is preferable to having the possibility of a deadlock.
    
    This patch also fixes a bug where it was possible to exit create_event()
    without releasing LOCK_event_metadata if running out of memory during
    its exection.
    
    No test case added since a repeatable test case would have required
    excessive use of new sync points. Instead we rely on the fact that
    this bug was easily reproduceable using RGQ tests.
    c7c1f219
events.cc 33.2 KB