From bf4244d1a0d921defbd92deb1e54b59ee1ce35b4 Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Wed, 27 Jun 2018 17:01:09 +0400 Subject: [PATCH 1/2] MDEV-8540 - Crash on server shutdown since 10.0.16 Only close stdin if it was open initinally. Otherwise we may close file descriptor which is reused for different puprose (specifically for binlog index file in case of this bug). --- sql/mysqld.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index fb49c05def5..d760986a303 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -5149,6 +5149,9 @@ int win_main(int argc, char **argv) int mysqld_main(int argc, char **argv) #endif { + /* We can't close stdin just now, because it may be booststrap mode. */ + bool please_close_stdin= fcntl(STDIN_FILENO, F_GETFD) >= 0; + /* Perform basic thread library and malloc initialization, to be able to read defaults files and parse options. @@ -5492,7 +5495,9 @@ int mysqld_main(int argc, char **argv) (char*) "" : mysqld_unix_port), mysqld_port, MYSQL_COMPILATION_COMMENT); - fclose(stdin); + /* Only close stdin if it was open initinally. */ + if (please_close_stdin) + fclose(stdin); #if defined(_WIN32) && !defined(EMBEDDED_LIBRARY) Service.SetRunning(); #endif From 3d4beee1a98cebd6eb566e38569e19599c2b9a98 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 28 Jun 2018 11:59:25 +0200 Subject: [PATCH 2/2] remove double-counting rnd_pos_by_record calls ha_rnd_pos, which does the counting --- sql/sql_class.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/sql/sql_class.h b/sql/sql_class.h index ec94f6c45d2..9428f6f6ce5 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -5012,8 +5012,6 @@ inline int handler::ha_ft_read(uchar *buf) inline int handler::ha_rnd_pos_by_record(uchar *buf) { int error= rnd_pos_by_record(buf); - if (!error) - update_rows_read(); table->status=error ? STATUS_NOT_FOUND: 0; return error; }