From 7bdc86a9cd58c6aadf267a72899554c36f88e684 Mon Sep 17 00:00:00 2001 From: jMyles Date: Sun, 26 Jul 2020 19:21:14 -0700 Subject: [PATCH] Making mature() a bit safer against reentrancy situations. Might still need a mutex. --- nucypher/network/nodes.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nucypher/network/nodes.py b/nucypher/network/nodes.py index 5afa23bde..61abe1fb3 100644 --- a/nucypher/network/nodes.py +++ b/nucypher/network/nodes.py @@ -75,6 +75,7 @@ class NodeSprout(PartiallyKwargifiedBytes): self.timestamp = maya.MayaDT( self.timestamp) # Weird for this to be in init. maybe this belongs in the splitter also. self._repr = None + self._is_finishing = False def __hash__(self): if not self._hash: @@ -113,14 +114,20 @@ class NodeSprout(PartiallyKwargifiedBytes): return self._nickname def mature(self): + # TODO: Something is fishy here. Another race condition maybe. Sometimes raises AttributeError because Ursula doesn't have _finished_values. + # This might need a mutex. + if self._is_finishing: + return self + self._is_finishing = True # Prevent reentrance. + mature_node = self.finish() + self.__class__ = mature_node.__class__ + self.__dict__ = mature_node.__dict__ # As long as we're doing egregious workarounds, here's another one. # TODO: 1481 filepath = mature_node._cert_store_function(certificate=mature_node.certificate) mature_node.certificate_filepath = filepath - self.__class__ = mature_node.__class__ - self.__dict__ = mature_node.__dict__ return self # To reduce the awkwardity of renaming; this is always the weird part of polymorphism for me.