-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Handle invalid ip address from cluster slots and added tests #7984
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,11 +170,11 @@ RedisCluster::RedisDiscoverySession::RedisDiscoverySession( | |
resolve_timer_(parent.dispatcher_.createTimer([this]() -> void { startResolveRedis(); })), | ||
client_factory_(client_factory), buffer_timeout_(0) {} | ||
|
||
namespace { | ||
// Convert the cluster slot IP/Port response to and address, return null if the response does not | ||
// match the expected type. | ||
Network::Address::InstanceConstSharedPtr | ||
ProcessCluster(const NetworkFilters::Common::Redis::RespValue& value) { | ||
RedisCluster::RedisDiscoverySession::RedisDiscoverySession::ProcessCluster( | ||
const NetworkFilters::Common::Redis::RespValue& value) { | ||
if (value.type() != NetworkFilters::Common::Redis::RespType::Array) { | ||
return nullptr; | ||
} | ||
|
@@ -187,12 +187,16 @@ ProcessCluster(const NetworkFilters::Common::Redis::RespValue& value) { | |
|
||
std::string address = array[0].asString(); | ||
bool ipv6 = (address.find(':') != std::string::npos); | ||
if (ipv6) { | ||
return std::make_shared<Network::Address::Ipv6Instance>(address, array[1].asInteger()); | ||
try { | ||
if (ipv6) { | ||
return std::make_shared<Network::Address::Ipv6Instance>(address, array[1].asInteger()); | ||
} | ||
return std::make_shared<Network::Address::Ipv4Instance>(address, array[1].asInteger()); | ||
} catch (const EnvoyException& ex) { | ||
ENVOY_LOG(warn, "Invalid ip address in CLUSTER SLOTS response: {}", ex.what()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would put this at debug as this comes from external input and might spam at high rate. Also do you want stat of some type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'll change this to debug. This would be tracked by cluster's update_failure stat. I think that's probably sufficient for now. |
||
return nullptr; | ||
} | ||
return std::make_shared<Network::Address::Ipv4Instance>(address, array[1].asInteger()); | ||
} | ||
} // namespace | ||
|
||
RedisCluster::RedisDiscoverySession::~RedisDiscoverySession() { | ||
if (current_request_) { | ||
|
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.
Sorry just realized, can you use
parseInternetAddress
here and avoid the ipv6 detection logic?/wait-any
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.
Thanks for letting me know, I don't know why I didn't find this function I last looked. Let me change that now.