Open anorm opened 2 years ago
Nolar gave me the advice that handlers should be fast acting: "[delete] handlers are supposed to be instant or at least fast (i.e. seconds)", or there could be unintended consequences. I'm assuming the same is true for timers, and that you're running into some of the "plethora of fancy side-effects and instability".
If you cannot shorten the operation of your timer and delete handler then you could make the delete handler return some value and check for that value (in status
) at the start of the delete handler to prevent repetition.
I'm trying to make the handlers as fast as possible. But sooner or later, this problem will arise, no matter how fast it is. My worry isn't necessarily that the delete handler is run twice, but that it is being executed before the timer is finished. This might cause the underlying object to mutate while the timer handler is running.
Ideally, I think the framework should guarantee that:
kopf.on.timer
should never fire before the completion of kopf.on.create
and kopf.on.resume
kopf.on.timer
should never execute after a kopf.on.delete
This way, handlers for different objects can run at the same time, while the complexity of writing a correctly working operator is reduced since no special care is needed (from the operator developer's perspective) to make deterministic behavior.
So, if I understand this correctly, @nolar, doesn't consider this a bug but leaves it up to the user to handle the concurrency issues. If that's the case, then I guess this github issue should be considered as a feature request :-)
Long story short
In an operator with both a
kopf.on.timer
and akopf.on.delete
, if the custom resource is deleted while the timer is invoked, the delete handler is called twice.I would expect the timer to be cancelled or that the current invocation was completed before the deletion handler is called.
Kopf version
1.35.3
Kubernetes version
1.22.4
Python version
Tested both on 3.9.9 and 3.10.1
Code
Logs
Additional information
The above was triggered using a single create and a single delete of a kubernetes custom resource. The
kubectl delete ...
did not exit before the second time the delete handler was invoked.Thank you for your great work! I really appreciate it!