Changing the response of the endpoint operation /wait after the lxd update

Hello everybody!

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04 LTS"

$ lxd --version
5.15
$ lxc ls test --fast
+-----------------------+---------+--------------+----------------------+-------------+-----------------+
|         NAME          |  STATE  | ARCHITECTURE |      CREATED AT      |  PROFILES   |      TYPE       |
+-----------------------+---------+--------------+----------------------+-------------+-----------------+
| test                  | STOPPED | x86_64       | 2023/08/15 04:56 UTC | default     | CONTAINER       |
$ INSTANCE_NAME=test && HOST_NAME='--unix-socket /var/snap/lxd/common/lxd/unix.socket' && OPERATION=`curl -s ${HOST_NAME} a/1.0/instances/${INSTANCE_NAME}/state -X PUT -d '{"action": "stop"}'  | jq -r '.operation'` && echo ${OPERATION} && curl -s ${HOST_NAME} a${OPERATION} | jq
{
  "type": "sync",
  "status": "Success",
  "status_code": 200,
  "operation": "",
  "error_code": 0,
  "error": "",
  "metadata": {
    "id": "2261fc7b-e031-4c09-b577-e13b7ecab256",
    "class": "task",
    "description": "Stopping instance",
    "created_at": "2023-08-15T14:15:55.082270524+07:00",
    "updated_at": "2023-08-15T14:15:55.082270524+07:00",
    "status": "Failure",
    "status_code": 400,
    "resources": {
      "instances": [
        "/1.0/instances/test"
      ]
    },
    "metadata": null,
    "may_cancel": false,
    "err": "The instance is already stopped",
    "location": "ironman"
  }
}

If we want to wait for the operation to complete, there will be an error

$ INSTANCE_NAME=test && HOST_NAME='--unix-socket /var/snap/lxd/common/lxd/unix.socket' && OPERATION=`curl -s ${HOST_NAME} a/1.0/instances/${INSTANCE_NAME}/state -X PUT -d '{"action": "stop"}'  | jq -r '.operation'` && echo ${OPERATION} && curl -s ${HOST_NAME} a${OPERATION}/wait | jq
/1.0/operations/1ff9645e-65e8-48a8-8c1a-6bdaecfd7749
{
  "type": "error",
  "status": "",
  "status_code": 0,
  "operation": "",
  "error_code": 500,
  "error": "The instance is already stopped",
  "metadata": null
}

Previously, the answer was the same with and without wait, but now code 500 has broken the logic of my application.

I will be grateful for any comments.

What status_code were you getting before?

I was getting code 400, exactly the same as without wait. Due to the fact that these two requests give different answers, I have to process them differently.
It seems to me that these queries should return the same result. And what code should be, what you give, and we will use it. :wink:

Thanks for your attention :+1:

@monstermunchkin please can you take a look at this and see if you can reproduce the inconsistency?

Thanks

I’ll take a look at this.

1 Like

https://github.com/canonical/lxd/issues/12214

The issue has been fixed. Thanks for reporting this.

https://github.com/canonical/lxd/pull/12218

1 Like

Thanks a lot, everybody. :+1:

1 Like