You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 1, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Jan 1, 2024. It is now read-only.
Vanity.playground.ab_assigned throws NoMethodError if Redis connection is down #328
While testing Vanity (2.2.7) behavior in situation when Redis is down, we discovered that the following code Vanity.playground.participant_info(vanity_identity) throws an error NoMethodError (undefined method to_i' for true:TrueClass):` with no stack trace in Vanity code.
We traced how the error and found a workaround, but it probably makes sense to get fixed on Vanity side.
Vanity.configuredo |config|
config.failover_on_datastore_error=trueconfig.on_datastore_error=Proc.newdo |error,klass,method,arguments|
Rails.logger.error("Vanity error: #{error}. Called by #{klass.inspect}, method #{method.inspect} with arguments #{arguments}")endend
If we add nil as return value of on_datastore_error callback, everything works ok. Without it, Rails.logger.error seems to return true which is being returned from ab_assigned and breaks participants_info method logic.
We are not sure how it should be fixed, probably documentation just should mention returning nil.
I wonder if we should instead be explicitly returning nil from call_redis_with_failover in the case of an exception? For example,
def call_redis_with_failover(*arguments)
calling_method = caller[0][/`.*'/][1..-2]
begin
yield
rescue => e
if Vanity.configuration.failover_on_datastore_error
Vanity.configuration.on_datastore_error.call(e, self.class, calling_method, arguments)
return nil # don't implicitly return the value returned by `on_datastore_error`
else
raise e
end
end
end
Another approach is to have a default_result parameter with default value as nil to give other methods calling call_redis_with_failover possibility to provide default return value to have more flexibility (some method would like to have [] or {} to be returned instead of nil). Though not sure whether this is needed and probably simple return nil would suffice.
Activity
phillbaker commentedon Jun 26, 2017
@kirhgoff thanks for the very detailed issue!
I wonder if we should instead be explicitly returning
nilfromcall_redis_with_failoverin the case of an exception? For example,kirhgoff commentedon Jun 27, 2017
Another approach is to have a default_result parameter with default value as nil to give other methods calling call_redis_with_failover possibility to provide default return value to have more flexibility (some method would like to have [] or {} to be returned instead of nil). Though not sure whether this is needed and probably simple return nil would suffice.