[MDEV-9836] Connection lost when using SSL Created: 2016-03-30  Updated: 2016-04-20  Resolved: 2016-04-20

Status: Closed
Project: MariaDB Server
Component/s: Platform Windows, SSL
Affects Version/s: 5.5, 10.0, 10.1
Fix Version/s: 5.5.49, 10.0.25, 10.1.14

Type: Bug Priority: Critical
Reporter: Vladislav Vaintroub Assignee: Sergei Golubchik
Resolution: Fixed Votes: 0
Labels: None
Environment:

YASSL, threadpool


Sprint: 5.5.49

 Description   

Client that is connected with SSL, that stays idle for a while, will be disconnected.
To reproduce

  • start the server with ssl, e.g

    perl mysql-test-run.pl ssl --start

  • connect with ssl client, e.g

    mysql -uroot --port=16000 --ssl

  • issue a command, e.g SELECT 1
  • wait 1 minute
  • repeat SELECT 1
  • see

    ERROR 2013 (HY000): Lost connection to MySQL server during query



 Comments   
Comment by Vladislav Vaintroub [ 2016-03-30 ]

The actual reason why the connection is lost seems to be a bug in yassl's implementation of SSL_pending(), which is called inside vio_ssl_has_data().
The socket is doing blocking recv() inside this function, and runs into net_read_timeout after a while. After that, connection breaks.

Doing blocking reads inside vio_ssl_has_data (or SSL_pending) does not sound like a great idea.

Below is the callstack of the blocking recv() calls

>Debug.ListCallStack /T:No /ShowByteOffset:No /ShowValues:No /ShowExternalCode:Yes
 Index  Function
--------------------------------------------------------------------------------
 1      ntdll.dll!_ZwWaitForSingleObject@12()
 2      mswsock.dll!_SockWaitForSingleObject@16()
 3      mswsock.dll!_WSPRecv@36()
 4      ws2_32.dll!_recv@16()
*5      mysqld.exe!yaSSL::Socket::wait()
 6      mysqld.exe!yaSSL::DoProcessReply(ssl)
 7      mysqld.exe!yaSSL::processReply(ssl)
 8      mysqld.exe!yaSSL::receiveData(ssl, data, peek)
 9      mysqld.exe!yaSSL_peek(ssl, buffer, sz)
 10     mysqld.exe!yaSSL_pending(ssl)
 11     mysqld.exe!vio_ssl_has_data(vio)
 12     mysqld.exe!threadpool_process_request(thd)
 13     mysqld.exe!io_completion_callback(instance, context, overlapped, io_result, nbytes, io)
 
 ---------------------------------------------------------------------------------
 1      mysqld.exe!vio_read(vio, buf, size)
 2      mysqld.exe!yassl_recv(ptr, buf, len, flag)
 3      mysqld.exe!yaSSL::Socket::receive(buf, sz, flags)
 4      mysqld.exe!yaSSL::DoProcessReply(ssl)
 5      mysqld.exe!yaSSL::processReply(ssl)
 6      mysqld.exe!yaSSL::receiveData(ssl, data, peek)
 7      mysqld.exe!yaSSL_peek(ssl, buffer, sz)
 8      mysqld.exe!yaSSL_pending(ssl)
 9      mysqld.exe!vio_ssl_has_data(vio)
 10     mysqld.exe!threadpool_process_request(thd)
 11     mysqld.exe!io_completion_callback(instance, context, overlapped, io_result, nbytes, io)

Generated at Thu Feb 08 07:37:41 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.