Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-4919

Packets out of order on a SELECT after calling a procedure with DELETE .. RETURNING

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 10.0.5
    • Component/s: None
    • Labels:
      None

      Description

      CREATE TABLE t1 (i INT);
      INSERT INTO t1 VALUES (1),(2);
      --delimiter |
      CREATE PROCEDURE p (a INT) 
      BEGIN
        DELETE FROM t1 WHERE i = a RETURNING *;
        INSERT INTO t1 VALUES (a);
      END |
      --delimiter ;
      
      CALL p(1);
      SELECT * FROM t1;
      
      MariaDB [test]> CALL p(1);
      +------+
      | i    |
      +------+
      |    1 |
      +------+
      1 row in set (0.03 sec)
      
      MariaDB [test]> SELECT * FROM t1;
      Error: Packets out of order (Found: 6, expected 1)
      ERROR 2013 (HY000): Lost connection to MySQL server during query
      MariaDB [test]> 
      

      The "Lost connection ..." error does not signify a server crash, only that the client got disconnected:

      ERROR 2013 (HY000): Lost connection to MySQL server during query
      MariaDB [test]> SELECT * FROM t1;
      ERROR 2006 (HY000): MySQL server has gone away
      No connection. Trying to reconnect...
      Connection id:    7
      Current database: test
      
      +------+
      | i    |
      +------+
      |    2 |
      |    1 |
      +------+
      2 rows in set (0.03 sec)
      

      bzr version-info

      revision-id: knielsen@knielsen-hq.org-20130816131025-etjrvmfvupsjzq83
      revno: 3674
      branch-nick: 10.0-base
      

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

              Hide
              psergey Sergei Petrunia added a comment -

              I have created a stored procedure P2() which is the same like the procedure P in the testcase, except that it has "SELECT * FROM t2" instead of DELETE ... RETURNING.

              When I debug two statements, I observe these differences:

              in mysql_execute_command(), sql_parse.cc:4354:
              P2:
              (gdb) p sp->m_flags
              $32 = 8 // this is sp_head::MULTI_RESULTS

              P:
              (gdb) p sp->m_flags
              $65 = 0

              if sp_head::MULTI_RESULTS is set, then the code right below sets SERVER_MORE_RESULTS_EXISTS in thd->server_status.

              This affects further execution. I've put breakpoints in relevant places:

              P2:
              Protocol::send_result_set_metadata flags=5
              Protocol::send_eof (this=0x474ade0, server_status=2090, statement_warn_count=0)
              (gdb) p/x server_status & 8
              $60 = 0x8
              Protocol::send_ok (this=0x474ade0, server_status=2082, statement_warn_count=0, affected_rows=1, last_insert_id=0, message=0x474f0ea "")

              P:
              Protocol::send_result_set_metadata (this=0x474ade0, list=0x7fff8c016980, flags=5)
              Protocol::send_eof (this=0x474ade0, server_status=2082, statement_warn_count=0)
              (gdb) p/x server_status & 8
              $66 = 0x0
              Protocol::send_ok (this=0x474ade0, server_status=2082, statement_warn_count=0, affected_rows=1, last_insert_id=0, message=0x474f0ea "")

              Show
              psergey Sergei Petrunia added a comment - I have created a stored procedure P2() which is the same like the procedure P in the testcase, except that it has "SELECT * FROM t2" instead of DELETE ... RETURNING. When I debug two statements, I observe these differences: in mysql_execute_command(), sql_parse.cc:4354: P2: (gdb) p sp->m_flags $32 = 8 // this is sp_head::MULTI_RESULTS P: (gdb) p sp->m_flags $65 = 0 if sp_head::MULTI_RESULTS is set, then the code right below sets SERVER_MORE_RESULTS_EXISTS in thd->server_status. This affects further execution. I've put breakpoints in relevant places: P2: Protocol::send_result_set_metadata flags=5 Protocol::send_eof (this=0x474ade0, server_status=2090, statement_warn_count=0) (gdb) p/x server_status & 8 $60 = 0x8 Protocol::send_ok (this=0x474ade0, server_status=2082, statement_warn_count=0, affected_rows=1, last_insert_id=0, message=0x474f0ea "") P: Protocol::send_result_set_metadata (this=0x474ade0, list=0x7fff8c016980, flags=5) Protocol::send_eof (this=0x474ade0, server_status=2082, statement_warn_count=0) (gdb) p/x server_status & 8 $66 = 0x0 Protocol::send_ok (this=0x474ade0, server_status=2082, statement_warn_count=0, affected_rows=1, last_insert_id=0, message=0x474f0ea "")
              Hide
              psergey Sergei Petrunia added a comment -

              This shows the error: when we run procedure P, we call send_eof() without SERVER_MORE_RESULTS_EXISTS. The client will get the EOF message and will not expect any further data. However, the server will later call send_ok(), which will cause client server protocol to go out of sync.

              Show
              psergey Sergei Petrunia added a comment - This shows the error: when we run procedure P, we call send_eof() without SERVER_MORE_RESULTS_EXISTS. The client will get the EOF message and will not expect any further data. However, the server will later call send_ok(), which will cause client server protocol to go out of sync.
              Hide
              psergey Sergei Petrunia added a comment -

              Committed a patch

              Show
              psergey Sergei Petrunia added a comment - Committed a patch
              Hide
              psergey Sergei Petrunia added a comment -

              Fix pushed to 10.0-base

              Show
              psergey Sergei Petrunia added a comment - Fix pushed to 10.0-base

                People

                • Assignee:
                  psergey Sergei Petrunia
                  Reporter:
                  elenst Elena Stepanova
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: