-
Notifications
You must be signed in to change notification settings - Fork 8
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
Added lock for EVC deletion #480
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Alopalao, nicely done finding and fixing this issue.
Overall the fix/approach is OK, but notice there's a thread safety issue that can still happen, I explained below, check it out, we'll need to cover that too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Alopalao, acquiring self._lock
(global consistency lock) can solve, but notice that this serializes entirely EVCs deletion which is an IO bound operation, so any concurrent deletions will have their performance significantly decreased. So, this isn't desirable to have in this case. EVC deletion should be safe per id, anything else that's not safe it's a problem that we need to solve. Let's go by parts and brainstorm with you:
1 - The self._load_evc(dict)
on consistency check, has never been thread safe per EVC (we could make it too but it's not worth it I'll elaborate on it) as you've found with this bug here. The easiest fix would be to just remove that last for loop that's trying to load evcs on consistency. EVCs should be only loaded during setup()
, this used to be here to aid in certain EVCs activations when EVCs didn't use to persist the active
state. I think we can safely remove this (in fact we could even remove more parts of the consistency as that will be refactored, but let's only remove the minimum part), can you try to remove that last for loop and reassess again if it fixes?
2 - Since you need to reove self._lock
from the EVC deletion, notice that there the problem of potential duplicated events might still come back, I'll recommend when popping
to check if it was popped while acquiring the evc.lock
and right after the lock if the EVC has been archived it means that another concurrent thread has already deleted it so you can early return with 200. See what I mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Alopalao, great updates. It's almost there, just a minor detail remaining, check out my comment. Also, don't forget to update the changelog and dispatch a final e2e exec, once it's passing it'll get approved and merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Leaving it pre-approved. Feel free to merge when e2e is passing.
Closes #478
Summary
Duplicated EVCs could happen. How?:
So these are the LOG messages from an EVC which got deployed by consistency check:
For an EVC deletion, first we pop the EVC from memory and then prepare EVC data to for its sync (DB deletion). While EVC was being prepared to be deleted, consistency check copied EVCs from memory (without popped EVC) and DB data (with EVC yet to be deleted). This caused it to be restored.
Local Tests
Run scripts again and no duplicated EVCs were found.
End-to-End Tests