-
Notifications
You must be signed in to change notification settings - Fork 80
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
Don't delegate to bulkhead, it might be nil #143
base: main
Are you sure you want to change the base?
Conversation
We might just want "allow_nil" here, not sure what the best behavior is. |
14426f3
to
6cc3bae
Compare
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.
Yeah, I think we should consider just doing allow_nil
. This is definitely an error, I don't think we should mock every call.
@@ -2,15 +2,15 @@ module Semian | |||
class ProtectedResource | |||
extend Forwardable | |||
|
|||
def_delegators :@bulkhead, :destroy, :count, :semid, :tickets, :registered_workers, :name | |||
def_delegators :@circuit_breaker, :reset, :mark_failed, :mark_success, :request_allowed?, |
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.
Shouldn't we do the same if the circuit breaker is disabled?
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.
Yeah i think both should just do allow_nil.
@sirupsen looks like |
What
Prevent a nil pointer dereference if attempting to read the name (or any other attribute delegated to bulkhead) of a protected resource without a bulkhead.
Why
Since bulkheads are now optional, we shouldn't delegate anything explicitly to them, as this can result in a nil pointer dereference.
How
The name is attempted to be read from the bulkhead first, falling back to the circuit breaker. If neither works, it will be nil, but it won't cause an exception to be raised from a nil pointer dereference.
Every other attribute has a safe accessor method defined, which will return a default value (same as for an unprotected resource) if there is no bulkhead.