Skip to content

Using map to store the listener in ConnectionHandlerImpl#19362

Merged
ggreenway merged 13 commits intoenvoyproxy:mainfrom
soulxu:using_map_for_conn_handler
Jan 24, 2022
Merged

Using map to store the listener in ConnectionHandlerImpl#19362
ggreenway merged 13 commits intoenvoyproxy:mainfrom
soulxu:using_map_for_conn_handler

Conversation

@soulxu
Copy link
Copy Markdown
Member

@soulxu soulxu commented Dec 29, 2021

Commit Message: Using map to store the listener in ConnectionHandlerImpl
Additional Description:
Risk Level: low
Testing: unittest
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: no

Signed-off-by: He Jie Xu hejie.xu@intel.com

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@soulxu soulxu closed this Dec 29, 2021
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@soulxu soulxu reopened this Dec 29, 2021
@soulxu soulxu requested a review from alyssawilk as a code owner December 29, 2021 12:06
EXPECT_CALL(*access_log_, log(_, _, _, _));
}

TEST_F(ConnectionHandlerTest, OldBehaviorMatchFirstWildcardListener) {
Copy link
Copy Markdown
Member Author

@soulxu soulxu Dec 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note for the reviewer, the original test ensure the first listener matched since the original code using the list. After using the unorder map, so this behavior changed. I assume the MatchFirst isn't part of API contract, so I remove it.

Copy link
Copy Markdown
Member Author

@soulxu soulxu Dec 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to this PR #16914, there should be no one depends on the matching order

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Dec 30, 2021

Thanks. It's great and added some comments. cc @rojkov

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Dec 30, 2021

/assign

@soulxu
Copy link
Copy Markdown
Member Author

soulxu commented Dec 30, 2021

@wbpcode thanks for the review!

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Dec 30, 2021

In addition, we may need distinguish the listener of different protocols. Check #17414.

soulxu added 2 commits January 3, 2022 13:15
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@soulxu
Copy link
Copy Markdown
Member Author

soulxu commented Jan 3, 2022

In addition, we may need distinguish the listener of different protocols. Check #17414.

thanks for another good point!

}

Network::InternalListenerOptRef
ConnectionHandlerImpl::findByAddress(const Network::Address::InstanceConstSharedPtr& address) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking to change this method name as findInternalListenerByAddress, since the assertion as below, this method is only used for internal listener.

@@ -224,58 +242,46 @@ ConnectionHandlerImpl::getBalancedHandlerByTag(uint64_t listener_tag) {

Network::BalancedConnectionHandlerOptRef
ConnectionHandlerImpl::getBalancedHandlerByAddress(const Network::Address::Instance& address) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also think about change this method name to getBalancedTCPHandlerByAddress, since this method is only used for TCP listener

@jmarantz
Copy link
Copy Markdown
Contributor

jmarantz commented Jan 4, 2022

After @wbpcode approves I'll assign to a maintainer for the next pass. Thanks!

Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good for me overall. And just some minor comments.

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@soulxu
Copy link
Copy Markdown
Member Author

soulxu commented Jan 6, 2022

This looks good for me overall. And just some minor comments.

thanks for the review!

@soulxu
Copy link
Copy Markdown
Member Author

soulxu commented Jan 10, 2022

@wbpcode appreciate if you can take a look at again!

wbpcode
wbpcode previously approved these changes Jan 10, 2022
Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. LGTM. cc @jmarantz @envoyproxy/envoy-maintainers

Some nit comments. But they are not worth blocking the review.

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Copy link
Copy Markdown
Member

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good. A few questions, and some comments to add. Thanks for fixing this scalability bottleneck!

/wait

if (listener.second.listener_->listenerTag() == listener_tag) {
listener.second.listener_->shutdownListener();
if (auto iter = listener_map_by_tag_.find(listener_tag); iter != listener_map_by_tag_.end()) {
if (iter->second->listener_->listener() != nullptr) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can it be in this map, and have a nullptr listener?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will stop the listener before draining it, the shutdownListener() https://github.com/envoyproxy/envoy/pull/19362/files#diff-fe538327af200510b78cadc759f2c3af989c822a370d3f8a005b92bc59568aa5R153 will reset the pointer. Then it is going to be nullptr. That means if we shutdown twice, then the second time you will see a nullptr.

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@soulxu
Copy link
Copy Markdown
Member Author

soulxu commented Jan 24, 2022

@ggreenway thanks for the review!

I addressed your comments except for #19362 (comment), but let me know if you expect the assertion used there.

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Copy link
Copy Markdown
Member

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Thanks!

@ggreenway ggreenway enabled auto-merge (squash) January 24, 2022 18:08
@ggreenway ggreenway merged commit 67c2b72 into envoyproxy:main Jan 24, 2022
@howardjohn
Copy link
Copy Markdown
Contributor

When upgrading our Istio test suites to this version everything started going a little wonky. I am not 100% sure what's happening but it looks like listeners are getting mixed up - calls are going to the wrong listeners as far as I can tell This is happening with bind_to_port=false. We were able to isolate the regression to this commit.

cc @lambdai

@mattklein123
Copy link
Copy Markdown
Member

It wouldn't surprise me if with bind_to_port = false we now have some ordering variability or something else. Feel free to revert this PR until we sort that out. cc @soulxu

@soulxu
Copy link
Copy Markdown
Member Author

soulxu commented Feb 3, 2022

I will do some tests on bind_to_port = false case. Then let you know when I figure out what happened.

@soulxu
Copy link
Copy Markdown
Member Author

soulxu commented Feb 3, 2022

When upgrading our Istio test suites to this version everything started going a little wonky. I am not 100% sure what's happening but it looks like listeners are getting mixed up - calls are going to the wrong listeners as far as I can tell This is happening with bind_to_port=false. We were able to isolate the regression to this commit.

cc @lambdai

@howardjohn do you have more failure info, or which testcase are failing. I checked the test, we have few tests on bind_to_port = false case

TEST_F(ConnectionHandlerTest, MatchIPv6WildcardListener) {

TEST_F(ConnectionHandlerTest, MatchLatestListener) {

I only thought the 0 port address can be a problem. But that shouldn't the case, since I can't create multiple 0 port addresses with bind_to_port as false.

@howardjohn
Copy link
Copy Markdown
Contributor

howardjohn commented Feb 3, 2022 via email

@soulxu
Copy link
Copy Markdown
Member Author

soulxu commented Feb 3, 2022

I could be wrong here

if (auto listener_it = tcp_listener_map_by_address_.find(address.asStringView());
listener_it != tcp_listener_map_by_address_.end()) {
return Network::BalancedConnectionHandlerOptRef(
listener_it->second->tcpListener().value().get());
}

I should check listener_it->second->listener_->listener() != nullptr, otherwise a draining listener could get new connection balanced to.

soulxu added a commit to soulxu/envoy that referenced this pull request Feb 4, 2022
…oyproxy#19362)"

This reverts commit 67c2b72.

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
joshperry pushed a commit to joshperry/envoy that referenced this pull request Feb 13, 2022
…19362)

Switch from list to map to avoid config load performance issues with large numbers of listeners.

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: Josh Perry <josh.perry@mx.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants