Bug #53899 Wrong mysql_stmt_errno() after connection loss with automatic reconnect
Submitted: 21 May 2010 18:58 Modified: 14 Oct 2010 15:28
Reporter: Staale Smedseng Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.1+ OS:Any
Assigned to: Staale Smedseng CPU Architecture:Any

[21 May 2010 18:58] Staale Smedseng
Description:
A client with automatic reconnect enabled will see the error message
"Lost connection to MySQL server during query" if the connection is
lost between mysql_stmt_prepare() and mysql_stmt_execute(). The
mysql_stmt_errno() number, however, is 0 -- not the corresponding
value 2013.

The error code is reset by set_stmt_errmsg() on return from
mysql_stmt_execute(). That is, it is actually set to the value of
net->last_errno, which by this time is 0 after a successful automatic
reconnect to the server.

This was missed in the fix for #43560.

How to repeat:
The attached simple client demonstrates the problem.
[21 May 2010 19:01] Staale Smedseng
Client program demonstrating the problem. Based on code from client in #43560.

Attachment: 53899.c (text/x-csrc), 1.34 KiB.

[25 Jun 2010 11:00] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/112201

3419 Staale Smedseng	2010-06-25
      Bug #53899 Wrong mysql_stmt_errno() after connection loss with
      automatic reconnect
      
      [This is a recommit of last week's commit which was missing a bug
      number in the commit message.]
      
      A client with automatic reconnect enabled will see the error message
      "Lost connection to MySQL server during query" if the connection is
      lost between mysql_stmt_prepare() and mysql_stmt_execute(). The
      mysql_stmt_errno() number, however, is 0 -- not the corresponding
      value 2013.
      
      This patch checks for the case where the prepared statement has been
      pruned due to a connection loss (i.e., stmt->mysql has been set to
      NULL) during a call to cli_advanced_command().
[29 Jun 2010 16:57] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/112494

3419 Staale Smedseng	2010-06-29
      Bug #53899 Wrong mysql_stmt_errno() after connection loss with
      automatic reconnect
      
      A client with automatic reconnect enabled will see the error
      message "Lost connection to MySQL server during query" if the
      connection is lost between mysql_stmt_prepare() and
      mysql_stmt_execute(). The mysql_stmt_errno() number, however,
      is 0 -- not the corresponding value 2013.
      
      This patch checks for the case where the prepared statement
      has been pruned due to a connection loss (i.e., stmt->mysql
      has been set to NULL) during a call to cli_advanced_command(),
      and avoids changing the last_errno to the result of the last
      reconnect attempt.
[30 Jun 2010 9:16] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/112532

3453 Staale Smedseng	2010-06-30
      Bug #53899 Wrong mysql_stmt_errno() after connection loss with
      automatic reconnect
      
      A client with automatic reconnect enabled will see the error
      message "Lost connection to MySQL server during query" if the
      connection is lost between mysql_stmt_prepare() and
      mysql_stmt_execute(). The mysql_stmt_errno() number, however,
      is 0 -- not the corresponding value 2013.
      
      This patch checks for the case where the prepared statement
      has been pruned due to a connection loss (i.e., stmt->mysql
      has been set to NULL) during a call to cli_advanced_command(),
      and avoids changing the last_errno to the result of the last
      reconnect attempt.
[19 Jul 2010 14:34] Bugs System
Pushed into 5.1.49 (revid:build@mysql.com-20100719143034-omcma40sblwmay3x) (version source revid:staale.smedseng@sun.com-20100630091606-5rh6s14mxh10fz62) (merge vers: 5.1.48) (pib:16)
[19 Jul 2010 19:17] Paul DuBois
Noted in 5.1.49 changelog.

A client with automatic reconnection enabled saw the error message
Lost connection to MySQL server during query if the connection was
lost between mysql_stmt_prepare() and mysql_stmt_execute(). However,
mysql_stmt_errno() returned 0, not the corresponding error number
2013.   

Setting report to Need Merge pending further pushes.
[23 Jul 2010 12:22] Bugs System
Pushed into mysql-trunk 5.5.6-m3 (revid:alik@sun.com-20100723121820-jryu2fuw3pc53q9w) (version source revid:vasil.dimov@oracle.com-20100531152341-x2d4hma644icamh1) (merge vers: 5.5.5-m3) (pib:18)
[23 Jul 2010 12:29] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100723121929-90e9zemk3jkr2ocy) (version source revid:vasil.dimov@oracle.com-20100531152341-x2d4hma644icamh1) (pib:18)
[23 Jul 2010 17:05] Paul DuBois
Noted in 5.5.6 changelog.
[14 Oct 2010 8:26] Bugs System
Pushed into mysql-5.1-telco-7.0 5.1.51-ndb-7.0.20 (revid:martin.skold@mysql.com-20101014082627-jrmy9xbfbtrebw3c) (version source revid:vasil.dimov@oracle.com-20100531152341-x2d4hma644icamh1) (merge vers: 5.5.5-m3) (pib:21)
[14 Oct 2010 8:41] Bugs System
Pushed into mysql-5.1-telco-6.3 5.1.51-ndb-6.3.39 (revid:martin.skold@mysql.com-20101014083757-5qo48b86d69zjvzj) (version source revid:vasil.dimov@oracle.com-20100531152341-x2d4hma644icamh1) (merge vers: 5.5.5-m3) (pib:21)
[14 Oct 2010 8:56] Bugs System
Pushed into mysql-5.1-telco-6.2 5.1.51-ndb-6.2.19 (revid:martin.skold@mysql.com-20101014084420-y54ecj85j5we27oa) (version source revid:vasil.dimov@oracle.com-20100531152341-x2d4hma644icamh1) (merge vers: 5.5.5-m3) (pib:21)
[14 Oct 2010 15:28] Jon Stephens
Already documented in the 5.1.49 changelog; no new changelog entries required. Setting back to Closed state.