fix(spell-bus): resubscribe spell on double subscription #1797
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.
Description
The
spell-event-bus
interface doesn't forbid subscription of the same spell on the same event on their own; the code around it was supposed to avoid such situations. However, there's a possibility that thesystem-service-deployer
can deploy system spells before thesorcerer
resubscribes old spells (created on the previous run of the node), so thesorcerer
can also resubscribe the newly created spells since we don't distinguish active and not-yet-active spells.This problem occurred during running nox in tests via
CreatedSwarm
and doesn't yet affect the fully-fledged nox.I think the best approach to the situation is to create a spell registry that would account for the spell's state: unsubscribed, subscribed, ended execution, etc. However, this approach requires more work and design and will be done in the future, but at the moment, we can introduce a simpler solution that won't resubscribe the running spells.
Motivation
The
spell-event-bus
doesn't track the list of active spells and will subscribe the already active spells as new ones. This can lead to running spells more often than configured.This problem can occur only at the start of the nox when the sorcerer resubscribes spells; the public interfaces (used by decider and direct deployment) aren't affected.
Proposed Changes