Skip to content

quic: postpone conn pool connect - #19860

Merged
RyanTheOptimist merged 26 commits into
envoyproxy:mainfrom
danzh2010:noconnectprodcodec
Feb 22, 2022
Merged

RyanTheOptimist merged 26 commits into
envoyproxy:mainfrom
danzh2010:noconnectprodcodec

Conversation

@danzh2010

@danzh2010 danzh2010 commented Feb 7, 2022 •

Copy link
Copy Markdown
Contributor

Commit Message: Currently H3 connection pool makes connect attempt during ActiveClient creation. So any network event during handshake won't be propagated to the pool because the network callbacks are not wired up yet. This change creates a type of CodecClient which doesn't call connect() during construction and uses it for H3 pool. The Http3::ConnectionPool::ActiveClient will defer connect() till next event loop.

Risk Level: medium, h3 connection pool only
Testing: existing tests pass
Runtime guard: envoy.reloadable_features.postpone_h3_client_connect_to_next_loop
Part of: #18715

@RyanTheOptimist RyanTheOptimist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks promising, but I don't think I understand what kinds of network events might be received during creation and why they necessarily need to be passed to the pool when they're generated (but only for HTTP/3). I suspect this is related to 0-RTT. Looking at the existing Grid tests, it looks like we already correctly handle the case where there is a failure during connect() so presumably that event is (somehow) handled successfully. Does that mechanism not work for the 0-RTT case?

uint32_t concurrent_stream_limit);
~ActiveClient() override;

virtual void onEnlisted() {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add a comment which explains when this is called (and what "enlisted" means in this context).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, great! I wonder if "initialized" might be more readable? WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ActiveClient already has a method called initialize() so I was trying to avoid similar names.

pending->cancel(Envoy::ConnectionPool::CancelPolicy::CloseExcess);
onPoolFailure(nullptr, absl::string_view(), ConnectionPool::PoolFailureReason::Overflow,
context);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add unit tests for the new code in this file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Modified h3 pool test and grid test to cover these changes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Having the h3 pool and grid pool tests cover this is good. I notice that we have conn_pool_base_test.cc so I'm wondering if we could add a ConnPoolImplBase test there. But maybe that file doesn't really have such tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a test in conn_pool_base_test.cc to verify the new way purges all pending streams.

pool->dispatcher(), pool->randomGenerator())
: std::make_unique<CodecClientProd>(CodecType::HTTP3, std::move(data.connection_),
data.host_description_, pool->dispatcher(),
pool->randomGenerator());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we unit test these changes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is covered in the grid test with parameterized the runtime guard.

Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
@RyanTheOptimist

Copy link
Copy Markdown
Contributor

This looks promising, but I don't think I understand what kinds of network events might be received during creation and why they necessarily need to be passed to the pool when they're generated (but only for HTTP/3). I suspect this is related to 0-RTT. Looking at the existing Grid tests, it looks like we already correctly handle the case where there is a failure during connect() so presumably that event is (somehow) handled successfully. Does that mechanism not work for the 0-RTT case?

Friendly ping?

@danzh2010

danzh2010 commented Feb 9, 2022 •

Copy link
Copy Markdown
Contributor Author

This looks promising, but I don't think I understand what kinds of network events might be received during creation and why they necessarily need to be passed to the pool when they're generated (but only for HTTP/3). I suspect this is related to 0-RTT. Looking at the existing Grid tests, it looks like we already correctly handle the case where there is a failure during connect() so presumably that event is (somehow) handled successfully. Does that mechanism not work for the 0-RTT case?

Currently network event during connect() is not propagate via network callbacks as connect() happens before that. They have been handled via checking if the connection gets closed during client creation and if yes, failing the client creation and propagate onPoolFailure() (see Http3::allocateConnPool). All these happens before the client object is added into one of the client lists in the pool. Unfortunately to handle 0-RTT connected event and max stream changed event, we want these signals to be propagated via the event callbacks rather than checking the client connection state at the end of creation because the former already has existing logic in conn pool but the latter doesn't, and the latter exposes too much 0-RTT specific connection states to the general conn pool comparing to a connection close event.

@RyanTheOptimist RyanTheOptimist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation! That makes a lot of sense. I think this looks pretty good. I do have one question about whether it might make sense to only have the "no connect" case in order to simplify things, but maybe that's problematic?

pending->cancel(Envoy::ConnectionPool::CancelPolicy::CloseExcess);
onPoolFailure(nullptr, absl::string_view(), ConnectionPool::PoolFailureReason::Overflow,
context);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Having the h3 pool and grid pool tests cover this is good. I notice that we have conn_pool_base_test.cc so I'm wondering if we could add a ConnPoolImplBase test there. But maybe that file doesn't really have such tests?

uint32_t concurrent_stream_limit);
~ActiveClient() override;

virtual void onEnlisted() {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, great! I wonder if "initialized" might be more readable? WDYT?

Comment thread source/common/http/http3/conn_pool.cc Outdated
ASSERT(codec_client_);
if (dynamic_cast<CodecClientProd*>(codec_client_.get()) == nullptr) {
// Hasn't called connect() yet.
codec_client_->connect();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Presumably this only happen in the case where the runtime flag is false? We could ASSERT() this here, but maybe that's not worth it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread test/common/http/conn_pool_grid_test.cc Outdated
TestScopedRuntime scoped_runtime;
Runtime::LoaderSingleton::getExisting()->mergeValues(
{{"envoy.reloadable_features.postpone_h3_client_connect_till_enlisted",
(GetParam() ? "true" : "false")}});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this the only test that uses the new parameterization? If so, I wonder if we can create a new test fixture for this class and just parameterize that to avoid running all the other tests twice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

ActiveClient& client_ref = *client;
LinkedList::moveIntoList(std::move(client), owningList(client->state()));
client_ref.onEnlisted();
if (client_ref.state() == ActiveClient::State::CLOSED) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm guessing this is needed because onEnlisted might call connect and that might fail? So this is basically the same case as up on line 146 but this is the "no connect" case, and that is the "connect" case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this if block handles connection close during connect(). But the one in 146 covers more than connect failure, but also the case where transport socket factory wasn't even finished config update during connection creation in H3.

context);
// This currently only happens for HTTP/3 if 1) secrets aren't yet loaded,
// or 2) connect failed immediately.
if (!pending_streams_.empty()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not quite sure I understand why this is needed, but wasn't needed before. Can you elaborate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Before pending wasn't purged so it got purged here. But now the connection close event callback would have purged all the pending streams.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

any chance we can just avoid this at the call site for (1) rather than here to avoid "sometimes done here, sometimes done elsewhere"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No longer has 2 failure cases, but the failure reason probably shouldn't be ConnectionPool::PoolFailureReason::Overflow as used here.


/**
* Production implementation that installs a real codec without automatically connecting.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if instead of having two different types of codeclients (one which calls connect and one which doesn't) if we could always go with this new "no connect" codepath. I'm wondering if we would be able to eliminate some complexity by only having one path? Maybe that's not feasible. What do you think?

@danzh2010

Copy link
Copy Markdown
Contributor Author

Thanks for the explanation! That makes a lot of sense. I think this looks pretty good. I do have one question about whether it might make sense to only have the "no connect" case in order to simplify things, but maybe that's problematic?

Are you thinking about changing CodecClientProd not to call connect() in its constructor? As to the codec client used in http1 and http2 conn pool, I guess their connect() can be postponed without problem. Even if not, I believe functionally we can always add a following connect() call to all its call sites.
However, we do have more use cases for a connected codec client rather than a non-connecting one. So calling CodecClient creation followed by connect() in those places seems not ideal.

@RyanTheOptimist

Copy link
Copy Markdown
Contributor

Thanks for the explanation! That makes a lot of sense. I think this looks pretty good. I do have one question about whether it might make sense to only have the "no connect" case in order to simplify things, but maybe that's problematic?

Are you thinking about changing CodecClientProd not to call connect() in its constructor? As to the codec client used in http1 and http2 conn pool, I guess their connect() can be postponed without problem. Even if not, I believe functionally we can always add a following connect() call to all its call sites. However, we do have more use cases for a connected codec client rather than a non-connecting one. So calling CodecClient creation followed by connect() in those places seems not ideal.

Yeah, that's what I was thinking. Thanks for explaining. I think that makes sense.

(Because GitHub code review is a bit tricky to follow, there are still a few outstanding comments. I'll take another look after they're addressed.)

@RyanTheOptimist

Copy link
Copy Markdown
Contributor

/wait-any

@RyanTheOptimist RyanTheOptimist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. Thanks!

@danzh2010

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #19860 (comment) was created by @danzh2010.

see: more, trace.

Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
@danzh2010

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Check envoy-presubmit isn't fully completed, but will still attempt retrying.
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #19860 (comment) was created by @danzh2010.

see: more, trace.

Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
alyssawilk
alyssawilk previously approved these changes Feb 17, 2022

@alyssawilk alyssawilk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cc @zuercher for !Google pass

*/
class NoConnectCodecClientProd : public CodecClient {
public:
NoConnectCodecClientProd(CodecType type, Network::ClientConnectionPtr&& connection,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK, how about a TODO to remove the extra class once the guard is deprecated then? It wasn't clear to me it was going away.

Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
@danzh2010

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #19860 (comment) was created by @danzh2010.

see: more, trace.

zuercher
zuercher previously approved these changes Feb 18, 2022

@zuercher zuercher left a comment

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.

lgtm, thanks!

Network::Connection& connection = *data.connection_;
auto client = std::make_unique<ActiveClient>(*pool, data);
if (connection.state() == Network::Connection::State::Closed) {
ASSERT(dynamic_cast<CodecClientProd*>(client->codec_client_.get()) != 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.

nit: I guess I'd add a note here about removing this conditional when the runtime flag is removed, but I don't think it gates approval.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Signed-off-by: Dan Zhang <[email protected]>
@danzh2010

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Check envoy-presubmit isn't fully completed, but will still attempt retrying.
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #19860 (comment) was created by @danzh2010.

see: more, trace.

@danzh2010

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #19860 (comment) was created by @danzh2010.

see: more, trace.

@danzh2010

Copy link
Copy Markdown
Contributor Author

Ping for merge

@danzh2010

Copy link
Copy Markdown
Contributor Author

@RyanTheOptimist for mege

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.

5 participants