Skip to content

quic: make 0-RTT keys truly shared by extending persistent quic info life time - #19862

Merged
alyssawilk merged 81 commits into
envoyproxy:mainfrom
danzh2010:h3pool0rtt
Mar 16, 2022
Merged

alyssawilk merged 81 commits into
envoyproxy:mainfrom
danzh2010:h3pool0rtt

Conversation

@danzh2010

@danzh2010 danzh2010 commented Feb 7, 2022 •

Copy link
Copy Markdown
Contributor

Commit Message: Move Quic::PersistentQuicInfoImpl instance into ClusterEntry to extends its life time.

Risk Level: low, quic connection pool only
Testing: existing tests pass
Fixes #19861
Part of #18715

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]>
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]>
Signed-off-by: Dan Zhang <[email protected]>

@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.

I stopped reviewing part way through the PR because it appears to have the changes from #19860 mixed in. Can you dis-entangle the PRs?

Comment thread envoy/http/BUILD Resolved
Comment thread envoy/network/connection.h Resolved
@danzh2010

danzh2010 commented Feb 8, 2022 •

Copy link
Copy Markdown
Contributor Author

I stopped reviewing part way through the PR because it appears to have the changes from #19860 mixed in. Can you dis-entangle the PRs?

Sorry, this PR fails tests without changes in #19860 because this one truly generates 0-RTT connect signal. I should have noted in this PR about the dependency. But I'd like to send it out to gather comments about moving around those objects while waiting on #19860.

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

Copy link
Copy Markdown
Contributor

Looks like the tests are failing? Should the "main" branch be changed to reference your 425 PR?

@danzh2010

Copy link
Copy Markdown
Contributor Author

Looks like the tests are failing? Should the "main" branch be changed to reference your 425 PR?

This change has nothing to do with router filter changes. I think the failure probably caused by the newly merged srtt caching change. Sync'ed with upstream now.

@danzh2010

Copy link
Copy Markdown
Contributor Author

I stopped reviewing part way through the PR because it appears to have the changes from #19860 mixed in. Can you dis-entangle the PRs?

Sorry, this PR fails tests without changes in #19860 because this one truly generates 0-RTT connect signal. I should have noted in this PR about the dependency. But I'd like to send it out to gather comments about moving around those objects while waiting on #19860.

I created danzh2010#221 with diff base from #19860. We can iterate there.

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]>
RyanTheOptimist
RyanTheOptimist previously approved these changes Mar 9, 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.

This looks so much cleaner now, thanks for diving into the larger refactor!

Upstream::ClusterConnectivityState& state, TimeSource& time_source,
AlternateProtocolsCacheSharedPtr alternate_protocols, ConnectivityOptions connectivity_options,
Quic::QuicStatNames& quic_stat_names, Stats::Scope& scope)
Quic::QuicStatNames& quic_stat_names, Stats::Scope& scope, Http::PersistentQuicInfo& quic_info)

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.

So now you've done all the plumbing I go and ask the inconvenient questions, but given we agree this is persistent info for the cluster, should we expose it via the cluster API rather than pass it in separately?

host_->cluster()->quicInfo or some such?

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.

Does this mean the quic info should live in ClusterInfoImpl object? I might be wrong but it seems to be shared across the workers. QUIC objects like alarm factory are not thread safe.

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 think we'd get thread local cluster, but given we'd still have to cast from the interface I can go either way here.

Comment thread source/common/http/http3/conn_pool.h Outdated
// Returns the most recent crypto config from host_;
std::shared_ptr<quic::QuicCryptoClientConfig> cryptoConfig();

// Store quic helpers which can be shared between connections and must live

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.

Should the comment be updated? Maybe just call out we're latching quic helpers shared across the cluster?

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


protected:
// fallback_factory_ will update the context.
void onSecretUpdated() override {}

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't we update here by implementing onSecretUpdated, instead of latching and comparing pointers?

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.

I think we used the lazy update because it was a bit tricky to add onSecretUpdated() to the callback list. Because fallback_factory_ provides the sslCtx object. We need to register this callback after the fallback_factory_ registered itself, which is during its construction, to ensure when onSecretUpdated() is triggered there is an updated sslCtx from the fallback_factory_ to use. But because fallback_factory_ owns the config object. After its construction, there is no non-const handle to the config object for this class to register onSecretUpdated().

I could have added a member variable to point to config object before passing it to fallback_factory_, but such handle short-lives the base class. So it's not a good model.

Comment thread envoy/http/persistent_quic_info.h Resolved
@alyssawilk

Copy link
Copy Markdown
Contributor

also check tidy?
/wait

@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 #19862 (comment) was created by @danzh2010.

see: more, trace.

Signed-off-by: Dan Zhang <[email protected]>
alyssawilk
alyssawilk previously approved these changes Mar 14, 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.

Tossing over to Greg for cluster refactors

@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 great to me, Dan!

@danzh2010

Copy link
Copy Markdown
Contributor Author

Ping @ggreenway

@danzh2010
danzh2010 dismissed stale reviews from RyanTheOptimist and alyssawilk via 8b2359a March 15, 2022 15:29

@ggreenway ggreenway 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.

Cluster refactor LGTM. I'll leave final approval to other reviewers.

@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 #19862 (comment) was created by @danzh2010.

see: more, trace.

@danzh2010

Copy link
Copy Markdown
Contributor Author

@alyssawilk for merge

@alyssawilk
alyssawilk enabled auto-merge (squash) March 16, 2022 12:40
@alyssawilk
alyssawilk merged commit d63c423 into envoyproxy:main Mar 16, 2022
ravenblackx pushed a commit to ravenblackx/envoy that referenced this pull request Jun 8, 2022
…life time (envoyproxy#19862)

Commit Message: Move Quic::PersistentQuicInfoImpl instance into ClusterEntry to extends its life time.

Risk Level: low, quic connection pool only
Testing: existing tests pass
Fixes envoyproxy#19861
Part of envoyproxy#18715

Signed-off-by: Dan Zhang <[email protected]>
mattklein123 pushed a commit that referenced this pull request Oct 20, 2026
…7893)

Commit Message: http3: keep the persistent QUIC info alive while its
pools use it
Additional Description:

Removing an HTTP/3 upstream cluster while it has requests in flight can
crash Envoy with a use-after-free in the QUIC client connection
(SIGSEGV/SIGBUS in `quic::QuicConnection::OnCanWrite` → `CanWrite`,
reached from `EnvoyQuicClientConnection::onFileEvent`, or from an
alarm).

`Quic::PersistentQuicInfoImpl` holds the QUIC helpers shared by a
cluster's HTTP/3 connections: the connection helper with its
`EnvoyQuicClock`, the alarm factory, the QUIC config, the crypto stream
factory and the writer factory. Since #19862 it is owned by the
thread-local `ClusterEntry` (`quic_info_`, a `unique_ptr`),
`Http3ConnPoolImpl` and `ConnectivityGrid` hold it by reference, and
every upstream QUIC connection keeps raw pointers into it
(`QuicConnection::clock_`, each alarm's clock). When CDS removes the
cluster, the worker erases the thread-local cluster and `~ClusterEntry`
calls `drainConnPools()` with `DrainAndDelete`, which lets busy clients
finish their streams, and then destroys its members, including the info.
The pools live on in `host_http_conn_pool_map_` until their streams end,
with connections pointing into freed memory; the next write-ready event
or alarm reads the freed clock. It needs streams in flight at the
removal, so it is intermittent. `Http3ConnPoolImpl`'s destructor already
makes sure connections are torn down before the pool drops the info; the
cluster entry's ordering was the gap.

Fix: `PersistentQuicInfoPtr` becomes a `shared_ptr`, and
`Http3ConnPoolImpl`, `Http3::allocateConnPool` and `ConnectivityGrid`
take and hold it instead of a reference. The cluster keeps creating and
holding the info and passes its pointer to the pools, so the info lives
until the last pool using it is gone (a pool destroys its connections
first). `createQuicNetworkConnection` still takes a reference; it is
only called by a pool that holds the info. No behavior change on a
healthy path.

Testing:
`Http3ConnPoolImplTest.PoolKeepsPersistentQuicInfoAliveAfterItsCreatorReleasesIt`
creates the info as the cluster manager does, builds a pool on it and
releases the creator's reference: the info must stay alive while the
pool exists and be freed with it (fails without the fix: freed at
release). The HTTP/3 pool, connection grid, cluster manager and QUIC
client connection factory tests and the QUIC HTTP and multiplexed
integration tests pass. Found through a crash on a deployment that
removed HTTP/3 clusters under load; the fault was symbolized to the
clock read in `QuicConnection::CanWrite`.

Verified on main (after #47806): the new test and the HTTP/3 pool and
grid tests pass, and CI is green.

Risk Level: low
Testing: unit test (new), existing HTTP/3 pool, grid, cluster manager
and QUIC integration tests
Docs Changes: N/A
Release Notes: bug_fixes
Platform Specific Features: N/A

---------

Signed-off-by: Bruno Palermo <[email protected]>
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.

quic: quic::SesssionCache and PersistentQuicInfo should outlive h3 conn pool

5 participants