-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack attribute in sceptre.hooks.Hook is not thread-safe #961
Labels
Comments
Hi @gilleswijnker , do you think you could contribute a PR to help resolve this issue? |
Hi @craighurley , sure I can. It will take some time because I'm quite busy at the moment. For anyone having the same issue, we have worked around this issue by getting the correct class CustomHook(Hook):
def run(self):
stack = self._get_stack()
self.lambda_handler(self.argument, stack)
# other methods, init etc.
@staticmethod
def _get_stack():
# Get reference to 'decorated' function in call stack. This is where sceptre hooks are applied.
# Moreover, the 'decorated' function has a reference to StackActions containing the correct Stack-instance.
fr = next(stack for stack in inspect.stack() if stack.function == 'decorated')[0]
args, _, _, value_dict = inspect.getargvalues(fr)
instance = value_dict['self'] if len(args) and args[0] == 'self' else None
return instance.stack if isinstance(instance, StackActions) else None |
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am using a custom Hook because I want to report the start and end time of updating our stacks. I also want to know the name of the Stack for which the Hook has been called. According to the documentation this is done with
self.stack.name
. See this simplified example:The content of
self.stack
seems to be overwritten by other concurrent running updates, probably because all use the sameCustomHook
-instance. So when I callself.stack.name
I am not getting the information of stack for which the Hook has been called, but the information of the latest stack that has been assigned to theCustomHook
-instance.To clarify this, I have added a print-statement to the
add_stack_hooks(func)
inhooks.__init__
:I have the following in my
config/config.yaml
:The output will be something like this (I have sanitized it to be readable):
Only one Hook has the correct
stack
available (thex/y/z
). The other four hooks all havea/b/c
asstack
, which is different than the one being updated. Note how these four all use the same hook-instance, which probably causes this problem.Because the correct stack is available in the
add_stack_hooks
-decorator, I suggest adding thestack
as parameter to theHook.run
method. Thestack
in the hook is than always the same as the one in the decorator. Also, sceptre can still get around with a limited amount of hook-instances. This would also mean thatHook.stack
is no longer needed:The text was updated successfully, but these errors were encountered: