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

Change delivery failure tracking to work with hostnames instead of URLs #13437

Merged
merged 1 commit into from Apr 15, 2020

Conversation

Gargron
Copy link
Member

@Gargron Gargron commented Apr 7, 2020

This should make reasoning about the behaviour of delivery failure tracking easier. It also ensures unavailable domains are not reset if Redis data is lost. By caching them through the Rails caching layer (which can potentially use a different Redis instance if configured correctly), it also helps memory usage, since a Redis instance configured for cache only can have a memory eviction policy.

@Gargron Gargron force-pushed the fix-unavailable-inboxes-hosts branch from 5072de4 to e6ad835 Compare April 7, 2020 22:17
app/lib/delivery_failure_tracker.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@ClearlyClaire ClearlyClaire left a comment

Choose a reason for hiding this comment

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

This seems like a good change overall, but I'm very worried about the part that loads everything from database, as this isn't bounded. This might grow large with time or even be vulnerable to attacks.

end

def days
Redis.current.scard(exhausted_deliveries_key) || 0
end

def available?
!UnavailableDomain.where(domain: @host).any?
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe

!UnavailableDomain.exists?(domain: @host)

arr.reject(&method(:unavailable?))
end
def without_unavailable(urls)
unavailable_domains_map = Rails.cache.fetch('unavailable_domains') { UnavailableDomain.pluck(:domain).each_with_object({}) { |domain, hash| hash[domain] = true } }
Copy link
Contributor

Choose a reason for hiding this comment

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

The number of unavailable domains could grow quite a bit, I'm not sure loading them all is safe…

Maybe caching a bloom filter instead, and then querying the database for domains that are possibly unavailable only would make more sense? Although rebuilding the bloom filter each time a domain is made available again would be costly…

Copy link
Member Author

Choose a reason for hiding this comment

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

You're not wrong but at the same time the number of distinct hostnames will be smaller than the current number of distinct inbox URLs. I think bloom filters are a nice idea but maybe something one could do down the line when this becomes practical bottleneck.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is true, but although I'm not sure how Redis handles large sets, I'd think it handles it better than just creating a big Ruby hash for it… honestly I'm not sure what's best here, but loading the whole thing really doesn't sound right.

@Gargron Gargron force-pushed the fix-unavailable-inboxes-hosts branch from 86b9376 to 2b6b9fa Compare April 15, 2020 17:55
@Gargron Gargron force-pushed the fix-unavailable-inboxes-hosts branch from 2b6b9fa to 71e534f Compare April 15, 2020 18:11
@Gargron Gargron merged commit 5edff32 into master Apr 15, 2020
@Gargron Gargron deleted the fix-unavailable-inboxes-hosts branch April 15, 2020 18:33
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.

None yet

3 participants