Fix a race condition in GCE’s list_nodes()#727
Closed
lhuard1A wants to merge 1 commit into
Closed
Conversation
| for i in v.get('instances', []): | ||
| try: | ||
| list_nodes.append(self._to_node(i)) | ||
| except ResourceNotFoundError: |
Contributor
There was a problem hiding this comment.
I think silently swallowing the exception justifies a comment :-)
Contributor
|
Thanks @lhuard1A for the contribution, please can you add a comment about the swallowed exceptions then I can merge this. |
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.
f49cea8 to
6d2b3cf
Compare
Contributor
Author
|
Thanks for the review @tonybaloney. |
Contributor
|
LGTM 👍 |
asfgit
pushed a commit
that referenced
this pull request
Apr 12, 2016
Signed-off-by: anthony-shaw <anthony.p.shaw@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Invoking GCE’s
list_nodes()while some VMs are being shutdown can resultin the following exception to be raised out of
list_nodes():The above error occurred while the
devops-regmachine was being deleted.The issue occurs when the following events happen in that order:
list_nodes()sends a request to list all the instances.At this point, the
devops-regwas still existing.devops-reginstance is deleted.list_nodes()calls_to_nodewhich callsex_get_volumewhich attempts to retrieve the information of the volumesBut, as the instance was deleted since it was listed,
ex_get_volumeraises aResourceNotFoundErrorexception.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.