You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by lhuard1A <gi...@git.apache.org> on 2016/03/25 17:32:18 UTC

[GitHub] libcloud pull request: Fix a race condition in GCE’s list_nodes(...

GitHub user lhuard1A opened a pull request:

    https://github.com/apache/libcloud/pull/727

    Fix a race condition in GCE’s list_nodes()

    Invoking GCE’s `list_nodes()` while some VMs are being shutdown can result
    in the following exception to be raised out of `list_nodes()`:
    
    ```
      File "/usr/lib/python2.7/site-packages/libcloud/compute/drivers/gce.py", line 1411, in list_nodes
        v.get('instances', [])]
      File "/usr/lib/python2.7/site-packages/libcloud/compute/drivers/gce.py", line 5065, in _to_node
        extra['boot_disk'] = self.ex_get_volume(bd['name'], bd['zone'])
      File "/usr/lib/python2.7/site-packages/libcloud/compute/drivers/gce.py", line 3982, in ex_get_volume
        response = self.connection.request(request, method='GET').object
      File "/usr/lib/python2.7/site-packages/libcloud/common/google.py", line 684, in request
        *args, **kwargs)
      File "/usr/lib/python2.7/site-packages/libcloud/common/base.py", line 736, in request
        response = responseCls(**kwargs)
      File "/usr/lib/python2.7/site-packages/libcloud/common/base.py", line 119, in __init__
        self.object = self.parse_body()
      File "/usr/lib/python2.7/site-packages/libcloud/common/google.py", line 259, in parse_body
        raise ResourceNotFoundError(message, self.status, code)
    libcloud.common.google.ResourceNotFoundError: {'domain': 'global', 'message': "The resource 'projects/lenaic/zones/europe-west1-c/disks/devops-reg' was not found", 'reason': 'notFound'}
    ```
    
    The above error occurred while the `devops-reg` machine was being deleted.
    
    The issue occurs when the following events happen in that order:
    
    * [`list_nodes()` sends a request to list all the instances.](https://github.com/apache/libcloud/blob/trunk/libcloud/compute/drivers/gce.py#L1622)
      At this point, the `devops-reg` was still existing.
    * The `devops-reg` instance is deleted.
    * `list_nodes()` calls `_to_node` which calls [`ex_get_volume` which attempts to retrieve the information of the volumes](https://github.com/apache/libcloud/blob/trunk/libcloud/compute/drivers/gce.py#L4235)
      But, as the instance was deleted since it was listed, `ex_get_volume` raises a `ResourceNotFoundError` exception.
    
    When this happens, we should simply discard the node that was deleted during the execution of `list_nodes()` and return the information about the other nodes.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/lhuard1A/libcloud fix_race_in_list_nodes

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/libcloud/pull/727.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #727
    
----
commit f49cea83cdb0ffe41b667a53a747f598ff90576d
Author: Lénaïc Huard <lh...@amadeus.com>
Date:   2016-03-25T16:00:48Z

    Fix a race condition in GCE’s list_nodes()
    
    Invoking GCE’s `list_nodes()` while some VMs are being shutdown can result
    in the following exception to be raised out of `list_nodes()`:
    
    ```
      File "/usr/lib/python2.7/site-packages/libcloud/compute/drivers/gce.py", line 1411, in list_nodes
        v.get('instances', [])]
      File "/usr/lib/python2.7/site-packages/libcloud/compute/drivers/gce.py", line 5065, in _to_node
        extra['boot_disk'] = self.ex_get_volume(bd['name'], bd['zone'])
      File "/usr/lib/python2.7/site-packages/libcloud/compute/drivers/gce.py", line 3982, in ex_get_volume
        response = self.connection.request(request, method='GET').object
      File "/usr/lib/python2.7/site-packages/libcloud/common/google.py", line 684, in request
        *args, **kwargs)
      File "/usr/lib/python2.7/site-packages/libcloud/common/base.py", line 736, in request
        response = responseCls(**kwargs)
      File "/usr/lib/python2.7/site-packages/libcloud/common/base.py", line 119, in __init__
        self.object = self.parse_body()
      File "/usr/lib/python2.7/site-packages/libcloud/common/google.py", line 259, in parse_body
        raise ResourceNotFoundError(message, self.status, code)
    libcloud.common.google.ResourceNotFoundError: {'domain': 'global', 'message': "The resource 'projects/lenaic/zones/europe-west1-c/disks/devops-reg' was not found", 'reason': 'notFound'}
    ```
    
    The above error occurred while the `devops-reg` machine was being deleted.
    
    The issue occurs when the following events happen in that order:
    
    * [`list_nodes()` sends a request to list all the instances.](https://github.com/apache/libcloud/blob/trunk/libcloud/compute/drivers/gce.py#L1622)
      At this point, the `devops-reg` was still existing.
    * The `devops-reg` instance is deleted.
    * `list_nodes()` calls `_to_node` which calls [`ex_get_volume` which attempts to retrieve the information of the volumes](https://github.com/apache/libcloud/blob/trunk/libcloud/compute/drivers/gce.py#L4235)
      But, as the instance was deleted since it was listed, `ex_get_volume` raises a `ResourceNotFoundError` exception.
    
    When this happens, we should simply discard the node that was deleted during the execution of `list_nodes()` and return the information about the other nodes.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] libcloud pull request: Fix a race condition in GCE’s list_nodes(...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/libcloud/pull/727


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---