Skip to content
  • Rahul Sisondia's avatar
    f7a4967b
    Bug#30889824 CLIENT FAILS WITH ERROR 2006 'MYSQL SERVER HAS GONE AWAY · f7a4967b
    Rahul Sisondia authored
                 INTERMITTENTLY
    
    Description
    -----------
    While nonblocking client is sending large packets, it is bound to happen that it
    may get EWOULDBLOCK error. That means "resource temporarily available"  so the
    client must  retry. Client has all that checks in place but the problem was
    using the wrong API for error  checking on Window.
    
    Fix
    ---
    To retrieve the last error code from sockets, client must call WSAGetLastError()
    instead of errno() API.  Refer the following text at
    https://docs.microsoft.com/en-us/windows/win32/winsock/error-codes-errno-h-errno-and-wsagetlasterror-2
    
    "
    Error codes set by Windows Sockets are not made available through the
    errno variable. Additionally, for the getXbyY class of functions, error
    codes are not made available through the h_errno variable. The WSAGetLastError()
    function is intended to provide a reliable way for a thread in a multithreaded
    process to obtain per-thread error information.
    "
    
    Sidenote
    --------
    I also changed the storage of query string from std::stringstream to std::string
    because test I found that test happened to fail on FreeBSD. Further
    investigation revealed that it happened due to pointer ownership violation.
    I was passing the stringstream.str().c_str() to the mysql_real_query_nonblocking
    API. This query pointer is  ultimately pointed by write buffer in the
    begin_packet_write_state() method.
    
     (*vec).iov_base = const_cast<uchar *>(packet);
    
    Notice that begin_packet_write_state() is called once in the nonblocking
    communication. That means (*vec).iov_base continues to point the
    string that has gone out of scope. It results in change in the packet content
    that server fails to  parse.
    
    Replaced the stringstream to string to avoid passing temporary string value to
    the API.
    
    Testing
    ----------
    Enabled the tests in mysql_client_test.test file.
    Verified the result locally.
    
    mysql-trunk-itch
    push id: 16089846
    Rahul Sisondia
    2020-03-27 14:13:17
    
    Review
    -------
    RB#24147
    f7a4967b
    Bug#30889824 CLIENT FAILS WITH ERROR 2006 'MYSQL SERVER HAS GONE AWAY
    Rahul Sisondia authored
                 INTERMITTENTLY
    
    Description
    -----------
    While nonblocking client is sending large packets, it is bound to happen that it
    may get EWOULDBLOCK error. That means "resource temporarily available"  so the
    client must  retry. Client has all that checks in place but the problem was
    using the wrong API for error  checking on Window.
    
    Fix
    ---
    To retrieve the last error code from sockets, client must call WSAGetLastError()
    instead of errno() API.  Refer the following text at
    https://docs.microsoft.com/en-us/windows/win32/winsock/error-codes-errno-h-errno-and-wsagetlasterror-2
    
    "
    Error codes set by Windows Sockets are not made available through the
    errno variable. Additionally, for the getXbyY class of functions, error
    codes are not made available through the h_errno variable. The WSAGetLastError()
    function is intended to provide a reliable way for a thread in a multithreaded
    process to obtain per-thread error information.
    "
    
    Sidenote
    --------
    I also changed the storage of query string from std::stringstream to std::string
    because test I found that test happened to fail on FreeBSD. Further
    investigation revealed that it happened due to pointer ownership violation.
    I was passing the stringstream.str().c_str() to the mysql_real_query_nonblocking
    API. This query pointer is  ultimately pointed by write buffer in the
    begin_packet_write_state() method.
    
     (*vec).iov_base = const_cast<uchar *>(packet);
    
    Notice that begin_packet_write_state() is called once in the nonblocking
    communication. That means (*vec).iov_base continues to point the
    string that has gone out of scope. It results in change in the packet content
    that server fails to  parse.
    
    Replaced the stringstream to string to avoid passing temporary string value to
    the API.
    
    Testing
    ----------
    Enabled the tests in mysql_client_test.test file.
    Verified the result locally.
    
    mysql-trunk-itch
    push id: 16089846
    Rahul Sisondia
    2020-03-27 14:13:17
    
    Review
    -------
    RB#24147
Loading