Comment 0 for bug 2060173

Revision history for this message
Wong Hong Han (honghan) wrote :

We have hit the issue where snap socket return more information in the result, causing vault version check break.

The function only get information from the last element in the returned information.

```
info = json.loads(
    snapd.recv(1024 * 1024).decode('utf-8').split('\n')[-1])
```

However I have hit some different response on the following version:
```
snap 2.61.2
snapd 2.61.2
```

Where the response become
```
['HTTP/1.1 200 OK\r', 'Content-Type: application/json\r', 'Date: Thu, 04 Apr 2024 03:38:20 GMT\r', 'Transfer-Encoding: chunked\r', '\r', '946\r', '{"type":"sync","status-code":200,"status":"OK","result":{"id": ... }]}}\r', '0\r', '\r', '']
```

Noticed there is 3 more elements in the end of the array, resulting the check failed.

A better approach is to check if the element has `vault` in it and parse accordingly.
```
original_info = snapd.recv(1024 * 1024).decode('utf-8').split('\n')
info = [ele for ele in original_info if "vault" in ele]
info = json.loads(info[0])
```