Bug #49334 add_to_status() race conditions
Submitted: 2 Dec 2009 10:19 Modified: 28 Jun 2010 9:13
Reporter: Sergei Golubchik Email Updates:
Status: Won't fix Impact on me:
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.1 OS:Any
Assigned to: Dmitry Shulga CPU Architecture:Any

[2 Dec 2009 10:19] Sergei Golubchik
add_to_status() that is used to add SHOW SESSION STATUS values to SHOW GLOBAL STATUS is not always protected by a mutex, and thus prone to race conditions.

How to repeat:


to add_to_status(), start mysqld.
The test suite won't even run the bootstrap step
[2 Dec 2009 11:06] Sveta Smirnova
Thank you for the report.

Verified as described.
[2 Dec 2009 11:36] Valeriy Kravchuk
This is what happens during bootstrap stage with recent 5.1.42-bzr:

openxs@suse:/home2/openxs/bzr/mysql-5.1-work> tail -100 mysql-test/var/log/bootstrap.log
/home2/openxs/bzr/mysql-5.1-work/sql/mysqld --no-defaults --bootstrap --basedir=/home2/openxs/bzr/mysql-5.1-work --datadir=/home2/openxs/bzr/mysql-5.1-work/mysql-test/var/install.db --loose-skip-innodb --loose-skip-falcon --loose-skip-ndbcluster --tmpdir=/home2/openxs/bzr/mysql-5.1-work/mysql-test/var/tmp/ --core-file --language=/home2/openxs/bzr/mysql-5.1-work/sql/share/english --character-sets-dir=/home2/openxs/bzr/mysql-5.1-work/sql/share/charsets
100309 18:13:16 [Note] Plugin 'FEDERATED' is disabled.
100309 18:13:16 [Note] Plugin 'InnoDB' is disabled.
100309 18:13:16 [Note] Plugin 'ndbcluster' is disabled.
100309 18:13:16 [Warning] /home2/openxs/bzr/mysql-5.1-work/sql/mysqld: unknown option '--loose-skip-falcon'
mysqld: sql_class.cc:1025: void add_to_status(STATUS_VAR*, STATUS_VAR*): Assertion `(&LOCK_status)->count > 0 && pthread_equal(pthread_self(), (&LOCK_status)->thread)' failed.
100309 18:13:16 - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 337727 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0x8a2c628
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0xbfffe59c thread_stack 0x30000
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at (nil) is an invalid pointer
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
Writing a core file
[7 May 2010 15:06] Mark Callaghan
If this is to be made thread safe, please provide an option to use atomic add rather than holding a mutex.
[23 Jun 2010 10:17] Konstantin Osipov
In cases when add_to_status() is not protected by LOCK_status it is protected by LOCK_thread_count. 
Dmitry, please add the respective assert and close the bug.
[28 Jun 2010 8:55] Konstantin Osipov
add_to_status() adds two arbitrary STATUS_VAR objects. Adding an assert to it would reduce its applicability.
The code was manually checked and proof-read to ensure that either LOCK_status or LOCK_thread_count or (sometimes) both are held while adding session statistics to the global statistics.
No further action is considered necessary at this point (in 5.1) (the code needs to be rewritten to address this and other issues.
Closing the bug as "Won't fix" as no real action will be done in 5.1.
[28 Jun 2010 9:13] Sergei Golubchik
What's the point of having "either LOCK_status or LOCK_thread_count" held ?

If one thread took LOCK_status and another took LOCK_thread_count - they can execute the critical section in parallel.

Which, precisely, means that it is not protected.