Skip to content
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

fix: Detect potential loops, don't eat errors #230

Merged
merged 4 commits into from
Jun 29, 2022
Merged

fix: Detect potential loops, don't eat errors #230

merged 4 commits into from
Jun 29, 2022

Conversation

jrconlin
Copy link
Member

simple loop detection for purge_old_records.py

@jrconlin jrconlin requested review from pjenvey and ethowitz June 22, 2022 22:05
@@ -54,6 +54,7 @@ def purge_old_records(config_file, grace_period=-1, max_per_loop=10,
try:
backend = config.registry.getUtility(INodeAssignment)
patterns = config.registry['endpoints_patterns']
previous_list = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be per service I believe (2 lines down)?

I'd argue this loop detection isn't really necessary after the last fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was debating moving it down, but then realized that we're detecting if things are the same. So any change would be fine so long as it didn't match the prior state. (And if we're doing things right, we're removing stuff along the way.)

If anything, loop detection should be nerf'd for "dry_run".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrm, there's no way to provide an offset to the backend.get_old_user_records, so dryrun will always return the same list. nerf'ing isn't possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's not likely to trigger a loop detected when iterating between services which will have different sets of users, but it also seems confusing to me to reuse the same state across them like that.

@jrconlin
Copy link
Member Author

Huh, but you did get me thinking about two services that might have empty results, which would raise a false exception.

Thanks!

if not rows:
logger.info("No more data for %s", service)
break
if [service].extend(rows) == previous_list:
Copy link
Member

@pjenvey pjenvey Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's [service] doing? extend is going to add on inplace, always returning None.

service here is a value on the user record but it's more of a foreign key to the services table. I don't think we actually use it, it's legacy from when tokenserver was built to support multiple services.

At one point we had a 'sync-1.1' and 'sync-1.5' protocols to support but I don't think tokenserver even used this feature to support that. Long story short, consider service to be unrelated, separated buckets of users on potentially different services.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have more than one service, there's the chance that we'd fail out early if a and b had no entries because [] == []. I just prefix the list with the service name so that we detect looping for a given service.

I don't expect it to trigger with what we're doing, but it's not a bad idea to handle it in any case, because I don't know who else might use this.

@pjenvey pjenvey merged commit 69d2ff6 into master Jun 29, 2022
@pjenvey pjenvey deleted the bug/loop branch June 29, 2022 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants