Bug #105989 channel_map's read lock is not unlocked
Submitted: 28 Dec 2021 7:49 Modified: 3 Jan 2022 12:29
Reporter: Cheng Zhou Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Replication Severity:S2 (Serious)
Version:8.0,8.0.27, 5.7 OS:Any
Assigned to: CPU Architecture:Any

[28 Dec 2021 7:49] Cheng Zhou
Description:
In function 'longlong Item_source_pos_wait::val_int()' in item_func.cc, the code segment:
--------------------------------------------------------
   ....
  channel_map.rdlock();

  if (arg_count == 4) {
    String *channel_str;
    if (!(channel_str = args[3]->val_str(&value))) {
      null_value = true;
      return 0;
    }

    ....

  } else {
    ....
  }
  ....
------------------------------------------------------

 When the args count is 4, and the fouth argument is NULL, channel_map's read lock is not unlocked.

How to repeat:
Connection 1:
select master_pos_wait('mysql-bin.000008',728,null,null);

Connection 2:
SHOW RELAYLOG EVENTS;

-------------------------------
The sql 'SHOW RELAYLOG EVENTS' would be blocked when it requires channel_map's write lock.

Suggested fix:
--------------------------------------------------------
   ....
  channel_map.rdlock();

  if (arg_count == 4) {
    String *channel_str;
    if (!(channel_str = args[3]->val_str(&value))) {
      channel_map.unlock();
      null_value = true;
      return 0;
    }

    ....

  } else {
    ....
  }
  ....
[30 Dec 2021 2:55] Cheng Zhou
modify version
[3 Jan 2022 12:29] MySQL Verification Team
Hello Cheng Zhou,

Thank you for the report and feedback.
Verified as described.

regards,
Umesh