Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

ObjectManager, providing resource.objects(), is not thread-safe #138

Open
miracle2k opened this issue Aug 16, 2017 · 0 comments
Open

ObjectManager, providing resource.objects(), is not thread-safe #138

miracle2k opened this issue Aug 16, 2017 · 0 comments

Comments

@miracle2k
Copy link

miracle2k commented Aug 16, 2017

The code in question is here:

pykube/pykube/objects.py

Lines 14 to 23 in e8a4629

class ObjectManager(object):
def __call__(self, api, namespace=None):
if namespace is None and NamespacedAPIObject in getmro(self.api_obj_class):
namespace = api.config.namespace
return Query(api, self.api_obj_class, namespace=namespace)
def __get__(self, obj, api_obj_class):
assert obj is None, "cannot invoke objects on resource object."
self.api_obj_class = api_obj_class
return self

The problem is that the code is expecting __get__ and __call__ to be executed in order. In https://github.com/miracle2k/k8s-snapshots we inadvertently ended up with a situation where that is not the case. Because we are watching two resources, in two separate threads, what happens during setup is that the methods are called in this order:

  • ObjectManager.get (for the PersistentVolume resource)
  • ObjectManager.get (for the PersistentVolumeClaim resource)
  • ObjectManager.call (for the PersistentVolume resource, but with self.api_obj_class set to PersistentVolumeClaim!)
  • ObjectManager.call (for the PersistentVolumeClaim resource)

In case it helps, a minimal example to reproduce this (Python 3.6) is here:

https://github.com/miracle2k/k8s-snapshots/tree/pykube-bug

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant