Valgrind Invalid File Descriptor In Syscall Close

Syscall

WL#11625: MTR: Review the VALGRIND warning patterns in mtrwarnings.sql file Affects: Server-8.0 — Status: Complete. If the data you need to attach is more than 3MB, you should create a compressed archive of the data and a README file that describes the data with a filename that includes the bug number (recommended filename: mysql-bug-data-50414.zip) and upload one to sftp.oracle.com.A free Oracle Web (SSO) account (the one you use to login bugs.mysql.com) and a client that supports SFTP are required in.

InvalidDescriptor

This shows up as a Valgrind warning

18197 Warning: invalid file descriptor -1 in syscall close()
18197 at 0x5F6E5BD: ??? (syscall-template.S:84)
18197 by 0xF95F34: inline_mysql_socket_close (mysql_socket.h:1090)
18197 by 0xF96AF3: vio_shutdown (viosocket.c:490)
18197 by 0x7C6BE0: THD::disconnect() (sql_class.cc:2057)
18197 by 0x637486: close_connection(THD*, unsigned int) (mysqld.cc:2886)
18197 by 0x7D63E3: do_handle_one_connection(THD*) (sql_connect.cc:1547)
18197 by 0x7D5E57: handle_one_connection (sql_connect.cc:1444)
18197 by 0xB98416: pfs_spawn_thread (pfs.cc:1860)
18197 by 0x5F656F9: start_thread (pthread_create.c:333)
18197 by 0x6B22B5C: clone (clone.S:109)

on e.g.

Valgrind Invalid File Descriptor In Syscall Closed

rpl.rpl_semi_sync_shutdown_hang 'mix' [ fail ] Found warnings/errors in server log file!
rpl.rpl_gtid_mts_relay_log_recovery_auto_pos_on_off 'mix' w3 [ fail ] Found warnings/errors in server log file!
rpl.rpl_report_port 'mix' w1 [ fail ] Found warnings/errors in server log file!
rpl.rpl_recovery_replicate_same_server_id 'mix' w4 [ fail ] Found warnings/errors in server log file!
rpl.rpl_change_master_crash_safe 'mix' w2 [ fail ] Found warnings/errors in server log file!
rpl.rpl_change_master 'mix' w1 [ fail ] Found warnings/errors in server log file!
rpl.rpl_alter_repository 'mix' w3 [ fail ] Found warnings/errors in server log file!
rpl.rpl_gtid_deployment_step 'mix' w1 [ fail ] Found warnings/errors in server log file!
rpl.rpl_recovery_replicate_same_server_id 'row' w4 [ fail ] Found warnings/errors in server log file!
main.mysql_client_test w4 [ fail ] Found warnings/errors in server log file!
auth_sec.mysql_native_plugin w3 [ fail ] Found warnings/errors in server log file!

Valgrind Invalid File Descriptor In Syscall Closer

Valgrind

The reason is that THD::disconnect is getting called twice, once from server thread-killing thread:
kill_server_threads -> kill_server -> close_connections -> close_connection -> THD::disconnect;
and the second time from the query thread itself, as in the above stacktrace.