Bug #82770 add() operation is not cancelled after returning an error
Submitted: 28 Aug 2016 19:02 Modified: 29 Aug 2016 8:56
Reporter: Daniël van Eeden (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Document Store: MySQL Shell Severity:S3 (Non-critical)
Version:1.0.4 OS:Any
Assigned to: CPU Architecture:Any

[28 Aug 2016 19:02] Daniël van Eeden
Description:
After returning 'MySQL Error (2000): Operation canceled' the add() can still succeed.

How to repeat:
SESSION 1:
mysql [localhost] {msandbox} (test) > lock tables t1 write;
Query OK, 0 rows affected (0.00 sec)

SESSION 2:
mysql-py> \use test
Schema `test` accessible through db.
mysql-py> db.t1.add({'foo': 'foobar'})
MySQL Error (2000): Operation canceled

(The error is returned after ~10s)

SESSION 1:
mysql [localhost] {msandbox} (test) > show processlist;
+----+----------+-----------------+------+---------+------+---------------------------------+------------------------------------------------------------------------------------------------------+
| Id | User     | Host            | db   | Command | Time | State                           | Info                                                                                                 |
+----+----------+-----------------+------+---------+------+---------------------------------+------------------------------------------------------------------------------------------------------+
| 47 | msandbox | localhost       | test | Query   |    0 | starting                        | show processlist                                                                                     |
| 48 | msandbox | localhost:60864 | test | Query   |   14 | Waiting for table metadata lock | PLUGIN: INSERT INTO `test`.`t1` (doc) VALUES (JSON_OBJECT('_id','ca172de1506de611997fac87a3027d34',' |
+----+----------+-----------------+------+---------+------+---------------------------------+------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql [localhost] {msandbox} (test) > unlock tables;
Query OK, 0 rows affected (0.00 sec)

SESSION 3:
mysql-py> db.t1.find()
[
    {
        "_id": "1e9ceb4c4e6de6110e7eac87a3027d34",
        "foo": "bar"
    },
    {
        "_id": "54ca4c504e6de6110e7eac87a3027d34",
        "foo2": "bar2"
    },
    {
        "_id": "ca172de1506de611997fac87a3027d34",
        "foo": "foobar"
    }
]
3 documents in set (0.00 sec)

(Note that the {'foo': 'foobar'} was added...)

Suggested fix:
Cancel backend operations when returning an error.
[28 Aug 2016 19:30] Daniël van Eeden
From the logfile:
2016-08-28 19:27:06: Warning: The key 'uuid' was not stored because is not valid
2016-08-28 19:27:42: Error: Operation canceled
2016-08-28 19:27:42: Error: Can't parse  Error (2000): Operation canceled

2016-08-28 19:27:42: Error: MySQL Error (2000): Operation canceled
[29 Aug 2016 8:56] Umesh Shastry
Hello Daniël,

Thank you for the report.

Thanks,
Umesh