-
Notifications
You must be signed in to change notification settings - Fork 342
Bypasseable Errors for Rack Attack Proxy Instances #689
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
base: main
Are you sure you want to change the base?
Conversation
nil | ||
def should_bypass_error?(error) | ||
# Dalli-specific default behavior: bypass Dalli errors | ||
return true if defined?(::Dalli::DalliError) && error.is_a?(Dalli::DalliError) |
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.
I like the idea to keep the existing behavior untouched, but maybe we can do something else to not have to override the should_bypass_error?
method here?
maybe something like having this DalliProxy have bypassable_store_errors
default to ['Dalli::DalliError']
as a String so that it doesn't fail if the gem is not installed?
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.
I think that's a good idea. Like you said, we could just define the bypassable_store_errors
and let the BaseProxy
class handle the rest.
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.
great, also we may need to decide if we want to let the rack attack user "remove" the default DalliError
being rescued by default but still rescue other errors I guess..
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.
Here I'm open to options. I think we could define the DalliError
as a predefined element in the bypassable_store_errors
and be explicit that if the user defines the bypassable_store_errors
then this would overwrite the default bypassable_errors
Hey @mpenalozag, sorry for the delay and thanks for working on this PR. I'm happy with the solution you are proposing, left just one comment for now. Would like to know what @grzuy thinks as well. And if we are all ok, then the PR would need tests and some changes to the README, of course. Thank you! |
class BaseProxy < SimpleDelegator | ||
attr_reader :bypass_all_store_errors, :bypassable_store_errors | ||
|
||
def initialize(store, bypass_all_store_errors: false, bypassable_store_errors: []) |
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.
wondering if it's better to have just one variable: bypassable_store_errors
which can either be a Symbol
(:all
or :none
), or an Array
? Just to avoid the possible combinations of both variable sets:
- bypass_all_store_errors: false, bypassable_store_errors: [...]
- bypass_all_store_errors: true, bypassable_store_errors: []
- bypass_all_store_errors: false, bypassable_store_errors: [...]
- bypass_all_store_errors: true, bypassable_store_errors: []
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.
I think that's a good approach. We could also raise a configuration error if both variables are defined. I think the one you mention is cleaner
@grzuy Hey! Just doing a follow up to this PR, hope you can check it soon |
Hey @mpenalozag, he may not be available at the time. So if you want we can go ahead with the PR 👍 |
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.
Hey there!
Sorry for the delay.
@mpenalozag thanks for you contribution!
Interested and eager to go a bit deeper on the issue/problem being addressed here and what others (if any) alternatives exit to address it, before considering adding a new feature that changes the public API in some way.
Can you elaborate on which particular proxy you're using and which errors in particular are making this a problem for you?
Thank you in advance!
attr_reader :store | ||
|
||
def store=(store) | ||
def store=(store, bypass_all_store_errors: false, bypassable_store_errors: []) |
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.
How would this be called from the caller?
Thinking about what the end user API would be.
@grzuy Thanks for your response! I'm specifically using the The project I'm working on handles payments, which is critical so I can't risk having this sort of issues. If anything fails I don't want the From the perspective of how would this be called by the end user API, since it's an
As for the options, I'm currently handling this on my project by wrapping the |
Description
Some errors on proxy instances could lead to requests not being passed to the next middleware. This could be behaviour that we want to avoid, we wouldn't want our system to stop responding just because of unexpected issues between Rack::Attack and our external Cache instance.
Considerations