Bug #46594 Backup fails to return ER_BACKUP_SEND_REPLY
Submitted: 6 Aug 2009 23:10 Modified: 20 Aug 2009 16:18
Reporter: Chuck Bell Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Backup Severity:S3 (Non-critical)
Version:5.4.4 OS:Any
Assigned to: Chuck Bell CPU Architecture:Any

[6 Aug 2009 23:10] Chuck Bell
Description:
The code in kernel.cc is designed to return an error if backup or restore operation is unable to send a reply to the client. See @line 358# in kernel.cc.

If you use debug insertion (see below), the server will crash. The problem appears in logger.cc @line#69 on the my_printf_error(error_code, msg, MYF(0)); call. Note that this is after the error has been handled by the debug insertion test (see below) and appears to be during closing of the stream object.

How to repeat:
You can reproduce the problem using this debug insertion:

@@ -332,6 +353,10 @@ int send_reply(Backup_restore_ctx &conte
     goto err;
   }
   my_eof(context.thd());                        // Never errors
+
+  // Error code insertion for ER_BACKUP_SEND_REPLY.
+  DBUG_EXECUTE_IF("ER_BACKUP_SEND_REPLY", goto err;);
+
   DBUG_RETURN(0);

And this test:

--echo #
--echo # Create database and data to test.
--echo #
CREATE DATABASE backup_test;
CREATE TABLE backup_test.t1 (a char(30)) ENGINE=MEMORY;
INSERT INTO backup_test.t1 VALUES ("01 Test Basic database example"); 
INSERT INTO backup_test.t1 VALUES ("02 Test Basic database example"); 
INSERT INTO backup_test.t1 VALUES ("03 Test Basic database example"); 
INSERT INTO backup_test.t1 VALUES ("04 Test Basic database example"); 
INSERT INTO backup_test.t1 VALUES ("05 Test Basic database example"); 
INSERT INTO backup_test.t1 VALUES ("06 Test Basic database example"); 
INSERT INTO backup_test.t1 VALUES ("07 Test Basic database example"); 

CREATE TABLE backup_test.t2 (a char(30)) ENGINE=MYISAM;
INSERT INTO backup_test.t2 VALUES ("11 Test Basic database example"); 
INSERT INTO backup_test.t2 VALUES ("12 Test Basic database example"); 
INSERT INTO backup_test.t2 VALUES ("13 Test Basic database example"); 

--echo #
--echo # Now create more database objects for test.
--echo #
CREATE PROCEDURE backup_test.p1(p1 CHAR(20))
  INSERT INTO backup_test.t1 VALUES ("50");

CREATE TRIGGER backup_test.trg AFTER INSERT ON backup_test.t1 FOR EACH ROW
 INSERT INTO backup_test.t1 VALUES('Test objects count');

CREATE FUNCTION backup_test.f1() RETURNS INT RETURN (SELECT 1);

CREATE VIEW backup_test.v1 as SELECT * FROM backup_test.t1;

CREATE EVENT backup_test.e1 ON SCHEDULE EVERY 1 YEAR DO
  DELETE FROM backup_test.t1 WHERE a = "not there";

--echo #
--echo # Now we need some privileges
--echo #
GRANT ALL ON backup_test.* TO 'joe'@'user';

--replace_column 1 #
BACKUP DATABASE backup_test TO 'orig.bak';

SET SESSION debug="+d,ER_BACKUP_SEND_REPLY";
--replace_column 1 #
--error ER_BACKUP_SEND_REPLY
BACKUP DATABASE backup_test TO '1.bak';
SET SESSION debug="-d";

Suggested fix:
Unknown.

After this problem is fixed, the test case can be enabled in backup_errors_debug_3.test using the following:

#
# Test case 53 requires running once for backup and once for restore.
#
# Test for error ER_BACKUP_SEND_REPLY.
LET $caseno = 53a;
LET $errno = $ER_BACKUP_SEND_REPLY;
LET $errname = ER_BACKUP_SEND_REPLY;
LET $operation = BACKUP;
--source suite/backup/include/test_for_error.inc

# Test for error ER_BACKUP_SEND_REPLY.
LET $caseno = 53b;
LET $errno = $ER_BACKUP_SEND_REPLY;
LET $errname = ER_BACKUP_SEND_REPLY;
LET $operation = RESTORE;
--source suite/backup/include/test_for_error.inc
[7 Aug 2009 14:32] Chuck Bell
Note: The code and test case are part of the patch for WL#4722. Once that is pushed, or made available, the test case can be enabled in backup_errors_debug_3.test and the code for the error condition insertion is active.
[11 Aug 2009 20:04] Chuck Bell
Chuck steals a bug from Rafal.
[20 Aug 2009 16:18] Chuck Bell
Alternative coding for WL#4722 has eliminated the bug report.