Skip to content

Commit 5ffc71d

Browse files
Aman Sharmameta-codesync[bot]
authored andcommitted
Use QuicExecutor in QMUX sessions
Summary: There is no functionality change in this commit. We're just swapping out the `folly::EventBase` for the `QuicExecutor`. Reviewed By: kvtsoy Differential Revision: D114159297 fbshipit-source-id: 0c8eec053174b0d8bab0fb40baaa180f6d9d57ac
1 parent 033e1bd commit 5ffc71d

10 files changed

Lines changed: 54 additions & 40 deletions

File tree

proxygen/lib/http/webtransport/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ proxygen_add_library(proxygen_http_webtransport_wt_util
9898
proxygen_http_codec_webtransport_webtransport_capsule_codec
9999
proxygen_http_webtransport_wt_stream_manager
100100
Folly::folly_executor
101-
Folly::folly_io_async_async_base
102101
)
103102

104103
proxygen_add_library(proxygen_http_webtransport_webtransport_session

proxygen/lib/http/webtransport/WtUtils.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#pragma once
1010

1111
#include <folly/Executor.h>
12-
#include <folly/io/async/EventBase.h>
1312
#include <proxygen/lib/http/codec/TransportDirection.h>
1413
#include <proxygen/lib/http/codec/webtransport/WebTransportCapsuleCodec.h>
1514
#include <proxygen/lib/http/webtransport/WtStreamManager.h>
@@ -211,10 +210,6 @@ class WtSessionBase : public WebTransport {
211210
return executor_;
212211
}
213212

214-
folly::EventBase* evb() {
215-
return dynamic_cast<folly::EventBase*>(executor_);
216-
}
217-
218213
protected:
219214
folly::Promise<folly::Unit>& uniCreditPromise() noexcept {
220215
return awaitUniCredit_;

proxygen/lib/transport/qmux/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,14 @@ proxygen_add_library(proxygen_transport_qmux_qmux_session
6363
proxygen_http_webtransport_wt_util
6464
proxygen_transport_qmux_qmux_framer
6565
proxygen_transport_qmux_qmux_transport
66-
Folly::folly_io_async_async_base
66+
mvfst::mvfst_common_events_quic_executor
6767
)
6868

6969
proxygen_add_library(proxygen_transport_qmux_qmux_connector
7070
SRCS
7171
QmuxConnector.cpp
7272
DEPS
7373
mvfst::mvfst_folly_utils
74-
Folly::folly_coro_timeout
75-
Folly::folly_futures_core
7674
Folly::folly_io_iobuf
7775
Folly::folly_logging_logging
7876
fmt::fmt
@@ -81,6 +79,7 @@ proxygen_add_library(proxygen_transport_qmux_qmux_connector
8179
proxygen_transport_qmux_qmux_framer
8280
proxygen_transport_qmux_qmux_session
8381
proxygen_transport_qmux_qmux_transport
82+
mvfst::mvfst_common_events_quic_executor
8483
Folly::folly_coro_task
8584
)
8685

proxygen/lib/transport/qmux/QmuxConnector.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88

99
#include <proxygen/lib/transport/qmux/QmuxConnector.h>
1010

11+
#include <chrono>
1112
#include <cstdint>
1213
#include <fmt/core.h>
13-
#include <folly/coro/Timeout.h>
14-
#include <folly/futures/ThreadWheelTimekeeper.h>
1514
#include <folly/io/Cursor.h>
1615
#include <folly/io/IOBufQueue.h>
1716
#include <folly/logging/xlog.h>
@@ -148,12 +147,21 @@ folly::coro::Task<QxTransportParams> readPeerTransportParams(
148147
QmuxTransport& transport,
149148
folly::IOBufQueue& ingressBuf,
150149
std::chrono::milliseconds timeout) {
150+
const auto deadline = std::chrono::steady_clock::now() + timeout;
151151
while (true) {
152+
const auto remaining =
153+
std::chrono::duration_cast<std::chrono::milliseconds>(
154+
deadline - std::chrono::steady_clock::now());
155+
if (remaining <= std::chrono::milliseconds::zero()) {
156+
co_yield co_error(
157+
std::runtime_error("timed out waiting for QX_TRANSPORT_PARAMETERS"));
158+
}
159+
152160
auto readRes = co_await folly::coro::co_awaitTry(
153161
transport.read(ingressBuf,
154162
/*minReadSize=*/1,
155163
/*newAllocationSize=*/4096,
156-
timeout));
164+
remaining));
157165
if (readRes.hasException()) {
158166
co_yield co_error(readRes.exception());
159167
}
@@ -194,7 +202,7 @@ WtStreamManager::WtConfig makeWtConfig(
194202
}
195203

196204
folly::coro::Task<QmuxSession::Ptr> QmuxConnector::connect(
197-
folly::EventBase* evb,
205+
std::shared_ptr<quic::QuicExecutor> executor,
198206
WtDir dir,
199207
QxTransportParams selfParams,
200208
std::unique_ptr<QmuxTransport> transport,
@@ -220,10 +228,9 @@ folly::coro::Task<QmuxSession::Ptr> QmuxConnector::connect(
220228
// timeout. peelTransportParams trims the TP frame and rewraps any
221229
// same-record trailing bytes so they parse cleanly downstream.
222230
folly::IOBufQueue ingressBuf{folly::IOBufQueue::cacheChainLength()};
223-
folly::EventBaseThreadTimekeeper tk{*evb};
224231

225-
auto peerParams = co_await folly::coro::co_awaitTry(folly::coro::timeout(
226-
readPeerTransportParams(*transport, ingressBuf, timeout), timeout, &tk));
232+
auto peerParams = co_await folly::coro::co_awaitTry(
233+
readPeerTransportParams(*transport, ingressBuf, timeout));
227234
if (peerParams.hasException()) {
228235
XLOG(ERR) << "QmuxConnector: TP read failed: " << peerParams.exception();
229236
co_yield co_error(peerParams.exception());
@@ -246,7 +253,7 @@ folly::coro::Task<QmuxSession::Ptr> QmuxConnector::connect(
246253
effectiveMaxIdleTimeoutMs = peerParams->maxIdleTimeout;
247254
}
248255

249-
co_return std::make_shared<QmuxSession>(evb,
256+
co_return std::make_shared<QmuxSession>(std::move(executor),
250257
dir,
251258
std::move(selfParams),
252259
std::move(transport),

proxygen/lib/transport/qmux/QmuxConnector.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414
#include <proxygen/lib/transport/qmux/QmuxFramer.h>
1515
#include <proxygen/lib/transport/qmux/QmuxSession.h>
1616
#include <proxygen/lib/transport/qmux/QmuxTransport.h>
17-
18-
namespace folly {
19-
class EventBase;
20-
} // namespace folly
17+
#include <quic/common/events/QuicExecutor.h>
2118

2219
namespace proxygen::qmux {
2320

2421
class QmuxConnector {
2522
public:
2623
static folly::coro::Task<QmuxSession::Ptr> connect(
27-
folly::EventBase* evb,
24+
std::shared_ptr<quic::QuicExecutor> executor,
2825
WtDir dir,
2926
QxTransportParams selfParams,
3027
std::unique_ptr<QmuxTransport> transport,

proxygen/lib/transport/qmux/QmuxSession.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class QmuxCallback : public QmuxCodec::Callback {
134134

135135
//////// QmuxSession ////////
136136

137-
QmuxSession::QmuxSession(folly::EventBase* evb,
137+
QmuxSession::QmuxSession(std::shared_ptr<quic::QuicExecutor> executor,
138138
WtDir dir,
139139
QxTransportParams selfParams,
140140
std::unique_ptr<QmuxTransport> transport,
@@ -144,7 +144,8 @@ QmuxSession::QmuxSession(folly::EventBase* evb,
144144
std::unique_ptr<folly::IOBuf> initialIngress,
145145
Config config)
146146
: CoroWtSessionBase(dir, wtConfig),
147-
WtSessionBase(evb, sm),
147+
WtSessionBase(executor.get(), sm),
148+
executor_(std::move(executor)),
148149
localAddr_(transport->getLocalAddress()),
149150
peerAddr_(transport->getPeerAddress()),
150151
transport_(std::move(transport)),
@@ -233,7 +234,7 @@ folly::coro::Task<void> QmuxSession::readLoop(Ptr self) {
233234
break;
234235
}
235236
}
236-
idleTimeout_.cancelTimeout();
237+
idleTimeout_.cancelTimerCallback();
237238
XLOG(DBG4) << "QmuxSession::readLoop exiting";
238239
sm.shutdown(WtStreamManager::CloseSession{.err = 0x00,
239240
.msg = "stream ingress closed"});
@@ -246,8 +247,8 @@ void QmuxSession::resetIdleTimeout() {
246247
// connection has no idle deadline. Nothing to do.
247248
return;
248249
}
249-
idleTimeout_.cancelTimeout();
250-
evb()->timer().scheduleTimeout(
250+
idleTimeout_.cancelTimerCallback();
251+
executor_->scheduleTimeout(
251252
&idleTimeout_, std::chrono::milliseconds(effectiveMaxIdleTimeoutMs_));
252253
}
253254

proxygen/lib/transport/qmux/QmuxSession.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
#pragma once
1010

1111
#include <deque>
12-
#include <folly/io/async/HHWheelTimer.h>
1312
#include <proxygen/lib/http/coro/util/CoroWtSession.h>
1413
#include <proxygen/lib/http/webtransport/WtStreamManager.h>
1514
#include <proxygen/lib/http/webtransport/WtUtils.h>
1615
#include <proxygen/lib/transport/qmux/QmuxFramer.h>
1716
#include <proxygen/lib/transport/qmux/QmuxTransport.h>
17+
#include <quic/common/events/QuicExecutor.h>
1818

1919
namespace folly {
2020
class AsyncTransport;
21-
}
21+
} // namespace folly
2222

2323
namespace proxygen::qmux {
2424

@@ -37,7 +37,7 @@ class QmuxSession
3737
public:
3838
using Ptr = std::shared_ptr<QmuxSession>;
3939

40-
QmuxSession(folly::EventBase* evb,
40+
QmuxSession(std::shared_ptr<quic::QuicExecutor> executor,
4141
WtDir dir,
4242
QxTransportParams selfParams,
4343
std::unique_ptr<QmuxTransport> transport,
@@ -46,6 +46,7 @@ class QmuxSession
4646
uint64_t effectiveMaxIdleTimeoutMs,
4747
std::unique_ptr<folly::IOBuf> initialIngress,
4848
Config config);
49+
4950
~QmuxSession() override;
5051

5152
void setHandler(WebTransportHandler* handler) {
@@ -77,7 +78,7 @@ class QmuxSession
7778
[[nodiscard]] folly::AsyncTransport* getUnderlyingTransport() const noexcept;
7879

7980
[[nodiscard]] bool isIdleTimeoutScheduled() const noexcept {
80-
return idleTimeout_.isScheduled();
81+
return idleTimeout_.isTimerCallbackScheduled();
8182
}
8283

8384
private:
@@ -90,19 +91,22 @@ class QmuxSession
9091
void resetIdleTimeout();
9192
void onIdleTimeout();
9293

93-
class IdleTimeoutCallback : public folly::HHWheelTimer::Callback {
94+
class IdleTimeoutCallback : public quic::QuicTimerCallback {
9495
public:
9596
explicit IdleTimeoutCallback(QmuxSession& session) noexcept
9697
: session_(session) {
9798
}
9899
void timeoutExpired() noexcept override {
99100
session_.onIdleTimeout();
100101
}
102+
void callbackCanceled() noexcept override {
103+
}
101104

102105
private:
103106
QmuxSession& session_;
104107
};
105108

109+
std::shared_ptr<quic::QuicExecutor> executor_;
106110
WebTransportHandler* wtHandler_{nullptr};
107111
folly::SocketAddress localAddr_;
108112
folly::SocketAddress peerAddr_;

proxygen/lib/transport/qmux/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ proxygen_add_test(TARGET QmuxSessionTest
4545
proxygen_http_codec_webtransport_webtransport_framer
4646
proxygen_http_webtransport_wt_stream_manager
4747
proxygen_http_webtransport_wt_util
48+
mvfst::mvfst_common_events_quic_folly_executor_impl
4849
TestCoroTransport
4950
testmain
5051
)
@@ -56,6 +57,7 @@ proxygen_add_test(TARGET QmuxConnectorTest
5657
proxygen_transport_qmux_qmux_connector
5758
proxygen_transport_qmux_folly_qmux_transport
5859
proxygen_transport_qmux_qmux_framer
60+
mvfst::mvfst_common_events_quic_folly_executor_impl
5961
TestCoroTransport
6062
testmain
6163
)

proxygen/lib/transport/qmux/test/QmuxConnectorTest.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <proxygen/lib/http/coro/transport/test/TestCoroTransport.h>
1616
#include <proxygen/lib/transport/qmux/FollyQmuxTransport.h>
1717
#include <proxygen/lib/transport/qmux/QmuxFramer.h>
18+
#include <quic/common/events/QuicFollyExecutorImpl.h>
1819

1920
using namespace proxygen;
2021
using namespace proxygen::qmux;
@@ -83,15 +84,19 @@ std::unique_ptr<folly::IOBuf> tpAndPingRecord(const QxTransportParams& params,
8384
// in a capturing lambda would dangle the captures once the lambda temporary
8485
// destructs at the call site.
8586
folly::coro::Task<void> connectAndCapture(
86-
folly::EventBase* evb,
87+
std::shared_ptr<quic::QuicExecutor> executor,
8788
WtDir dir,
8889
QxTransportParams selfParams,
8990
std::unique_ptr<QmuxTransport> transport,
9091
std::chrono::milliseconds timeout,
9192
folly::Try<QmuxSession::Ptr>* out,
9293
bool* done) {
93-
*out = co_await folly::coro::co_awaitTry(QmuxConnector::connect(
94-
evb, dir, std::move(selfParams), std::move(transport), timeout));
94+
*out = co_await folly::coro::co_awaitTry(
95+
QmuxConnector::connect(std::move(executor),
96+
dir,
97+
std::move(selfParams),
98+
std::move(transport),
99+
timeout));
95100
*done = true;
96101
}
97102

@@ -113,8 +118,8 @@ class QmuxConnectorTest : public ::testing::Test {
113118
QxTransportParams selfParams = sampleSelfParams()) {
114119
folly::Try<QmuxSession::Ptr> result;
115120
bool done = false;
116-
co_withExecutor(&evb_,
117-
connectAndCapture(&evb_,
121+
co_withExecutor(executor_.get(),
122+
connectAndCapture(executor_,
118123
WtDir::Client,
119124
std::move(selfParams),
120125
std::make_unique<FollyQmuxTransport>(
@@ -130,6 +135,8 @@ class QmuxConnectorTest : public ::testing::Test {
130135
}
131136

132137
folly::EventBase evb_;
138+
std::shared_ptr<quic::QuicFollyExecutorImpl> executor_{
139+
std::make_shared<quic::QuicFollyExecutorImpl>(&evb_)};
133140
};
134141

135142
} // namespace

proxygen/lib/transport/qmux/test/QmuxSessionTest.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <proxygen/lib/transport/qmux/FollyQmuxTransport.h>
1818
#include <proxygen/lib/transport/qmux/QmuxCodec.h>
1919
#include <proxygen/lib/transport/qmux/QmuxFramer.h>
20+
#include <quic/common/events/QuicFollyExecutorImpl.h>
2021

2122
using namespace proxygen;
2223
using namespace proxygen::qmux;
@@ -273,7 +274,7 @@ class QmuxSessionTest : public ::testing::Test {
273274
.peerMaxStreamDataUni = peerParams.initialMaxStreamDataUni};
274275

275276
session_ = std::make_shared<QmuxSession>(
276-
&evb_,
277+
executor_,
277278
WtDir::Server,
278279
selfParams,
279280
std::make_unique<FollyQmuxTransport>(std::move(transport)),
@@ -338,6 +339,8 @@ class QmuxSessionTest : public ::testing::Test {
338339
static constexpr uint64_t kPeerBidiId = 0x00;
339340

340341
folly::EventBase evb_;
342+
std::shared_ptr<quic::QuicFollyExecutorImpl> executor_{
343+
std::make_shared<quic::QuicFollyExecutorImpl>(&evb_)};
341344
std::unique_ptr<TestCoroTransport::State> state_;
342345
TestCoroTransport* transport_{nullptr};
343346
std::unique_ptr<TestWtHandler> handler_;
@@ -492,7 +495,7 @@ TEST_F(QmuxSessionTest, InitialIngress_IsDrainedOnStartup) {
492495
auto preroll = streamRecord(kPeerBidiId, "preroll", /*fin=*/false);
493496

494497
auto session = std::make_shared<QmuxSession>(
495-
&evb_,
498+
executor_,
496499
WtDir::Server,
497500
selfParams_,
498501
std::make_unique<FollyQmuxTransport>(std::move(transport)),
@@ -598,7 +601,7 @@ TEST_F(QmuxSessionTest, IdleTimer_ArmedWhenEffectiveTimeoutNonzero) {
598601
.peerMaxStreamDataUni = 1 << 16};
599602

600603
auto session = std::make_shared<QmuxSession>(
601-
&evb_,
604+
executor_,
602605
WtDir::Server,
603606
selfParams_,
604607
std::make_unique<FollyQmuxTransport>(std::move(transport)),

0 commit comments

Comments
 (0)