Uploaded image for project: 'CloudStack'
  1. CloudStack
  2. CLOUDSTACK-10320

Invalid pair for response object breaking response parsing

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • API
    • Security Level: Public (Anyone can view this level - this is the default.)
    • None

    Description

      Under some circumstances, the API is returning an invalid response, for simplicity I will expose the JSON case. The API response on a listVirtualMachines can be this string:

      { "listvirtualmachinesresponse" :  ] } }

      To understand how this is possible, assume you have more than one management server and one is processing the destroy of a virtual machine in the account X which is the only one it has. Another process is returning the result of listVirtualMachines for that same account X. During the listVM command, the result set is fetch with a searchAndDistinctCount due to the view (https://github.com/apache/cloudstack/blob/master/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java#L1024). This is done through 2 queries in the GenericDao https://github.com/apache/cloudstack/blob/master/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java#L1323 and if you encounter the right conditions, the VM will be marked as removed in between those 2 queries. This results in having a Pair result with at least one object but a count of 0. Then following how is done the serialization of the response at https://github.com/apache/cloudstack/blob/master/server/src/main/java/com/cloud/api/response/ApiResponseSerializer.java#L86 you will reach the case where your output is the one previously mentioned.

      To overcome this issue, there isn't a true fix but only a better pair response to ensure a correct response formatting. If the result set contains at least something, the count cannot be 0 but we cannot guess the correct answer, but only state it has at least one element.

      Attachments

        Issue Links

          Activity

            People

              marcaurele Marc-Aurèle Brothier
              marcaurele Marc-Aurèle Brothier
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: