Bug #88299 csv:binlog corruption, abort, An error occurred during flush stage of the commit
Submitted: 30 Oct 2017 15:39
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: CSV Severity:S1 (Critical)
Version:5.7.17 OS:Windows
Assigned to: CPU Architecture:Any

[30 Oct 2017 15:39] Shane Bester
Description:
Affects release builds of 5.7.

Symptoms are:

1.  Some user queries error out with strange errors:
    Error writing file 'UNOPENED' (Errcode: 9 - Bad file descriptor)

2. Inexplicable crashes like this:

[ERROR] mysqld: Binary logging not possible. Message: An error occurred during flush stage of the commit. 'binlog_error_action' is set to 'ABORT_SERVER'. Hence aborting the server.
15:26:28 UTC - mysqld got exception 0x80000003 ;
mysqld.exe!my_sigabrt_handler()[my_thr_init.c:449]
  ucrtbase.DLL!raise()
  ucrtbase.DLL!abort()
mysqld.exe!exec_binlog_error_action_abort()[binlog.cc:1858]
mysqld.exe!MYSQL_BIN_LOG::handle_binlog_flush_or_sync_error()[binlog.cc:9105]
mysqld.exe!MYSQL_BIN_LOG::ordered_commit()[binlog.cc:9325]
mysqld.exe!MYSQL_BIN_LOG::commit()[binlog.cc:8529]
mysqld.exe!ha_commit_trans()[handler.cc:1796]
mysqld.exe!trans_commit_stmt()[transaction.cc:459]
mysqld.exe!mysql_execute_command()[sql_parse.cc:5005]
mysqld.exe!mysql_parse()[sql_parse.cc:5588]
mysqld.exe!dispatch_command()[sql_parse.cc:1460]
mysqld.exe!do_command()[sql_parse.cc:1000]
mysqld.exe!handle_connection()[connection_handler_per_thread.cc:300]
mysqld.exe!pfs_spawn_thread()[pfs.cc:2193]
mysqld.exe!win_thread_start()[my_thread.c:38]

3.  When trying to restart mysqld,  it may fail to recognize its own binary logs,  or the binlog .index file is containing trash...

[Note] Plugin 'FEDERATED' is disabled.
[ERROR] Binlog has bad magic number;  It's not a binary log file that can be used by this version of MySQL
[ERROR] Can't init tc log
[ERROR] Aborting

How to repeat:
Testcase must be run like this, exactly.

1. mysqld --max-binlog-size=1M --binlog-format=STATEMENT --log-bin --server-id=1

2. Create the schema:

reset master;
drop database if exists test;
create database test;
use test;
drop table if exists `t1`;
create table `t1` (`c0000` varbinary(100) not null) engine=csv;
create table t2 like t1;

3.  Import the testcase:
 mysql -uroot --force test --binary-mode < /tmp/t.sql

Repeat as needed, since sometimes it doesn't crash..

If above does not satisfactorily repeat problems,  simply run a random DML testcase on the table with random data and insert/delete/update/replace/select.
[31 Oct 2017 5:47] MySQL Verification Team
it looks windows specific so far...
[31 Oct 2017 7:02] MySQL Verification Team
Since this is a windows problem, I enabled Application Verifier (appverif.exe).
Here's the first report.

PRIMARY_PROBLEM_CLASS:  STATUS_INVALID_HANDLE
BUGCHECK_STR:  APPLICATION_FAULT_STATUS_INVALID_HANDLE

 Call Site
 ntdll!KiRaiseUserExceptionDispatcher+0x3a
 vfbasics+0x19558
 KERNELBASE!SetFilePointerEx+0x93
 kernel32!SetFilePointerExStub+0x9
 mysqld!my_win_lseek+0x29 [.\mysql-5.7.20\mysys\my_winfile.c @ 409]
 mysqld!my_seek+0x26 [.\mysql-5.7.20\mysys\my_seek.c @ 64]
 mysqld!inline_mysql_file_seek+0xaf [.\mysql-5.7.20\include\mysql\psi\mysql_file.h @ 1243]
 mysqld!Transparent_file::init_buff+0x32 [.\mysql-5.7.20\storage\csv\transparent_file.cc @ 39]
 mysqld!ha_tina::init_data_file+0xab [.\mysql-5.7.20\storage\csv\ha_tina.cc @ 1159]
 mysqld!ha_tina::rnd_init+0x1e [.\mysql-5.7.20\storage\csv\ha_tina.cc @ 1199]
 mysqld!handler::ha_rnd_init+0x12 [.\mysql-5.7.20\sql\handler.cc @ 2897]
 mysqld!init_read_record+0x2d1 [.\mysql-5.7.20\sql\records.cc @ 314]
 mysqld!Sql_cmd_delete::mysql_delete+0xa66 [.\mysql-5.7.20\sql\sql_delete.cc @ 412]
 mysqld!Sql_cmd_delete::execute+0xc9 [.\mysql-5.7.20\sql\sql_delete.cc @ 1382]
 mysqld!mysql_execute_command+0x1865 [.\mysql-5.7.20\sql\sql_parse.cc @ 3571]
 mysqld!mysql_parse+0x273 [.\mysql-5.7.20\sql\sql_parse.cc @ 5583]
 mysqld!dispatch_command+0x713 [.\mysql-5.7.20\sql\sql_parse.cc @ 1464]
 mysqld!do_command+0x1ea [.\mysql-5.7.20\sql\sql_parse.cc @ 1001]
 mysqld!handle_connection+0x12c [.\mysql-5.7.20\sql\conn_handler\connection_handler_per_thread.cc @ 300]
 mysqld!pfs_spawn_thread+0x132 [.\mysql-5.7.20\storage\perfschema\pfs.cc @ 2193]
 mysqld!win_thread_start+0x1c [.\mysql-5.7.20\mysys\my_thread.c @ 38]