Bug #91304 mysqlsh generates invalid JSON when quorum lost
Submitted: 18 Jun 2018 14:36 Modified: 6 Sep 2018 12:25
Reporter: Andrew Pryde Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Document Store: MySQL Shell Severity:S3 (Non-critical)
Version:8.0.11 OS:Any
Assigned to: CPU Architecture:Any

[18 Jun 2018 14:36] Andrew Pryde
Description:
MySQL shell is generating non-valid JSON when calling dba.get_cluster().status() when quorum has been lost since it escapes the single quotes in "Cluster has no quorum as visible from '127.0.0.1:3306'".

How to repeat:
 - Start a simple cluster with a single primary, 3 members total
 - Kill 2 of the 3 members without deleting the underlying data for the members. This causes the cluster to lose quorum.

Connect via mysqlsh and execute:

> s = dba.get_cluster().status()
> print s
{"clusterName": "MySQLCluster", "defaultReplicaSet": {"name": "default", "primary": "mysql-0.mysql:3306", "ssl": "REQUIRED", "status": "NO_QUORUM", "statusText": "Cluster has no quorum as visible from \'127.0.0.1:3306\' and cannot process write transactions. 2 members are not active", "topology": {"mysql-0.mysql:3306": {"address": "mysql-0.mysql:3306", "mode": "R/W", "readReplicas": {}, "role": "HA", "status": "UNREACHABLE"}, "mysql-1.mysql:3306": {"address": "mysql-1.mysql:3306", "mode": "R/O", "readReplicas": {}, "role": "HA", "status": "UNREACHABLE"}, "mysql-2.mysql:3306": {"address": "mysql-2.mysql:3306", "mode": "R/O", "readReplicas": {}, "role": "HA", "status": "ONLINE"}}}, "groupInformationSourceMember": "mysql://root@127.0.0.1:3306"}
>
> import json
> json.loads(str(s))
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.7/json/decoder.py", line 382, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Invalid \escape: line 1 column 202 (char 201)

Suggested fix:
Don't escape https://github.com/mysql/mysql-shell/blob/02f74a53ff4c9a4eab3d411b8263d940263f9169/modules...)
[6 Sep 2018 12:25] David Moss
Posted by developer:
 
Thank you for your feedback, this has been fixed in upcoming versions and the following was added to the 8.0.13 changelog:
The result of calling dba.get_cluster().status() when quorum was lost could not be converted to a JSON object, because the string representation of the resultant object contained escape sequences. This issue was not limited to the Cluster.status() method, but affected all arrays and dictionaries returned by the Shell API in Python mode. The internal representation of arrays and dictionaries has been fixed.