Bug #103196 Reading GLOBAL variables without locking
Submitted: 2 Apr 2021 15:24 Modified: 6 Apr 2021 9:37
Reporter: Luis Donoso Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: CPU Architecture:Any

[2 Apr 2021 15:24] Luis Donoso
Description:
Some global variables are read without locking what could be a data race if
another thread is processing a `set global` operation.

For instance, the variable `binlog_cache_size` in
https://github.com/mysql/mysql-server/blob/7ed30a748964c009d4909cb8b4b22036ebdef239/sql/bi...

How to repeat:
It is difficult to replicate as it depends on whether the architecture performs a write in one instruction or not.

Suggested fix:
Before reading a global variable the lock `LOCK_global_system_variables` should be owned.
[5 Apr 2021 13:19] MySQL Verification Team
Hi Mr. Donoso,

Thank you for your bug report.

However, this is not a bug.

On all architectures that we support, this operation is atomic, for all 64-big integers. This is a reason why we have a proper casting in all such places.

Not a bug.
[6 Apr 2021 9:37] Luis Donoso
Please, I kindly request the status to be open.

There is another problem related with no using barriers.

As there are no barriers controlling the access to the variable, the compiler assumes just one thread access to the variable and can apply optimizations like do not read the value from the RAM if the value is already in the cache which would cause some threads may use a stale value of the variable.

Please, find more info about this problem in https://stackoverflow.com/a/1351902