-
Notifications
You must be signed in to change notification settings - Fork 5.5k
upstream: Null-deref on TCP health checker if setsockopt fails #6793
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
Changes from 7 commits
ab89ac2
609cfec
413fe8a
14c343c
f3fda0e
1b95a69
d0a53bf
9acd444
260074f
57d549c
b77ef7d
2eaee67
5721aca
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 |
|---|---|---|
|
|
@@ -252,6 +252,9 @@ class TcpHealthCheckerImpl : public HealthCheckerImplBase { | |
| TcpHealthCheckerImpl& parent_; | ||
| Network::ClientConnectionPtr client_; | ||
| std::shared_ptr<TcpSessionCallbacks> session_callbacks_; | ||
| // If true, stream reset was initiated by us, not e.g. remote reset. | ||
| // In this case healthcheck status already reported, only state cleanup required. | ||
| bool expect_reset_{}; | ||
|
Member
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. nit: can you make this
Contributor
Author
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. Done |
||
| }; | ||
|
|
||
| typedef std::unique_ptr<TcpActiveHealthCheckSession> TcpActiveHealthCheckSessionPtr; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2336,7 +2336,7 @@ TEST_F(TcpHealthCheckerImplTest, WrongData) { | |
| Host::ActiveHealthFailureType::UNHEALTHY); | ||
| } | ||
|
|
||
| TEST_F(TcpHealthCheckerImplTest, Timeout) { | ||
| TEST_F(TcpHealthCheckerImplTest, TimeoutThenRemoteClose) { | ||
| InSequence s; | ||
|
|
||
| setupData(); | ||
|
|
@@ -2396,6 +2396,66 @@ TEST_F(TcpHealthCheckerImplTest, Timeout) { | |
| cluster_->prioritySet().getMockHostSet(0)->runCallbacks({}, removed); | ||
| } | ||
|
|
||
| TEST_F(TcpHealthCheckerImplTest, DoubleTimeout) { | ||
| InSequence s; | ||
|
|
||
| setupData(); | ||
| health_checker_->start(); | ||
|
|
||
| expectSessionCreate(); | ||
| expectClientCreate(); | ||
| cluster_->prioritySet().getMockHostSet(0)->hosts_ = { | ||
| makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; | ||
| EXPECT_CALL(*connection_, write(_, _)); | ||
| EXPECT_CALL(*timeout_timer_, enableTimer(_)); | ||
|
|
||
| cluster_->prioritySet().getMockHostSet(0)->runCallbacks( | ||
| {cluster_->prioritySet().getMockHostSet(0)->hosts_.back()}, {}); | ||
|
|
||
| connection_->raiseEvent(Network::ConnectionEvent::Connected); | ||
|
|
||
| Buffer::OwnedImpl response; | ||
| add_uint8(response, 1); | ||
| read_filter_->onData(response, false); | ||
|
|
||
| EXPECT_CALL(*connection_, close(_)); | ||
| EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, true)); | ||
| EXPECT_CALL(*timeout_timer_, disableTimer()); | ||
| EXPECT_CALL(*interval_timer_, enableTimer(_)); | ||
|
mattklein123 marked this conversation as resolved.
|
||
| timeout_timer_->callback_(); | ||
| EXPECT_EQ(cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->getActiveHealthFailureType(), | ||
| Host::ActiveHealthFailureType::TIMEOUT); | ||
| EXPECT_EQ(Host::Health::Healthy, cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->health()); | ||
|
|
||
| expectClientCreate(); | ||
| EXPECT_CALL(*connection_, write(_, _)); | ||
| EXPECT_CALL(*timeout_timer_, enableTimer(_)); | ||
| interval_timer_->callback_(); | ||
|
|
||
| connection_->raiseEvent(Network::ConnectionEvent::Connected); | ||
|
|
||
| EXPECT_CALL(*connection_, close(_)); | ||
| EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); | ||
| EXPECT_CALL(*timeout_timer_, disableTimer()); | ||
| EXPECT_CALL(*interval_timer_, enableTimer(_)); | ||
| timeout_timer_->callback_(); | ||
| EXPECT_EQ(cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->getActiveHealthFailureType(), | ||
| Host::ActiveHealthFailureType::TIMEOUT); | ||
| EXPECT_EQ(Host::Health::Unhealthy, cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->health()); | ||
|
Contributor
Author
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. Here's where I check that two timeouts in a row cause us to mark this host unhealthy |
||
|
|
||
| expectClientCreate(); | ||
| EXPECT_CALL(*connection_, write(_, _)); | ||
| EXPECT_CALL(*timeout_timer_, enableTimer(_)); | ||
| interval_timer_->callback_(); | ||
|
|
||
| connection_->raiseEvent(Network::ConnectionEvent::Connected); | ||
|
|
||
| HostVector removed{cluster_->prioritySet().getMockHostSet(0)->hosts_.back()}; | ||
| cluster_->prioritySet().getMockHostSet(0)->hosts_.clear(); | ||
| EXPECT_CALL(*connection_, close(_)); | ||
| cluster_->prioritySet().getMockHostSet(0)->runCallbacks({}, removed); | ||
| } | ||
|
|
||
| // Tests that when reuse_connection is false timeouts execute normally. | ||
| TEST_F(TcpHealthCheckerImplTest, TimeoutWithoutReusingConnection) { | ||
| InSequence s; | ||
|
|
@@ -2585,6 +2645,33 @@ TEST_F(TcpHealthCheckerImplTest, PassiveFailureCrossThreadRemoveClusterRace) { | |
| EXPECT_EQ(0UL, cluster_->info_->stats_store_.counter("health_check.passive_failure").value()); | ||
| } | ||
|
|
||
| TEST_F(TcpHealthCheckerImplTest, ConnectionLocalFailure) { | ||
| InSequence s; | ||
|
|
||
| setupData(); | ||
| cluster_->prioritySet().getMockHostSet(0)->hosts_ = { | ||
| makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; | ||
| expectSessionCreate(); | ||
| expectClientCreate(); | ||
| EXPECT_CALL(*connection_, write(_, _)); | ||
| EXPECT_CALL(*timeout_timer_, enableTimer(_)); | ||
| health_checker_->start(); | ||
|
|
||
| // Expect the LocalClose to be handled as a health check failure | ||
| EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, true)); | ||
| EXPECT_CALL(*timeout_timer_, disableTimer()); | ||
| EXPECT_CALL(*interval_timer_, enableTimer(_)); | ||
|
|
||
| // Raise a LocalClose that is not triggered by the health monitor itself. | ||
| // e.g. a failure to setsockopt(). | ||
| connection_->raiseEvent(Network::ConnectionEvent::LocalClose); | ||
|
|
||
| EXPECT_EQ(1UL, cluster_->info_->stats_store_.counter("health_check.attempt").value()); | ||
| EXPECT_EQ(0UL, cluster_->info_->stats_store_.counter("health_check.success").value()); | ||
| EXPECT_EQ(1UL, cluster_->info_->stats_store_.counter("health_check.failure").value()); | ||
| EXPECT_EQ(0UL, cluster_->info_->stats_store_.counter("health_check.passive_failure").value()); | ||
| } | ||
|
|
||
| class TestGrpcHealthCheckerImpl : public GrpcHealthCheckerImpl { | ||
| public: | ||
| using GrpcHealthCheckerImpl::GrpcHealthCheckerImpl; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.