Skip to content

Commit c8e435a

Browse files
hanidamlajfacebook-github-bot
authored andcommitted
simplify WebTransportImpl::terminateSessionStreams
Summary: rewrites WebTransportImpl::terminateSessionStreams for simplicity Reviewed By: joanna-jo Differential Revision: D83162525 fbshipit-source-id: 8dfc2057e0716ff3a826fcff3ff25eb3ed745d6d
1 parent 912c44a commit c8e435a

File tree

3 files changed

+15
-29
lines changed

3 files changed

+15
-29
lines changed

proxygen/lib/http/session/test/HTTPTransactionWebTransportTest.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -495,15 +495,14 @@ TEST_F(HTTPTransactionWebTransportTest, StreamDetachWithOpenStreams) {
495495
});
496496
readCancelled = true;
497497
});
498-
folly::CancellationCallback writeCancel(
499-
res->writeHandle->getCancelToken(), [&writeCancelled, &res, this] {
500-
VLOG(4) << "writeCancelled";
501-
EXPECT_CALL(transport_, resetWebTransportEgress(0, WT_APP_ERROR_2));
502-
res->writeHandle->resetStream(WT_APP_ERROR_2);
503-
writeCancelled = true;
504-
});
498+
folly::CancellationCallback writeCancel(res->writeHandle->getCancelToken(),
499+
[&] {
500+
VLOG(4) << "writeCancelled";
501+
writeCancelled = true;
502+
});
505503
HTTPException ex(HTTPException::Direction::INGRESS_AND_EGRESS, "aborted");
506504
handler_.expectError();
505+
EXPECT_CALL(transport_, resetWebTransportEgress(0, _));
507506
EXPECT_CALL(
508507
transport_,
509508
stopReadingWebTransportIngress(0, makeOpt(WebTransport::kInternalError)));

proxygen/lib/http/webtransport/WebTransportImpl.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,23 @@ void WebTransportImpl::destroy() {
3333

3434
void WebTransportImpl::terminateSessionStreams(uint32_t errorCode,
3535
const std::string& reason) {
36-
// These loops are dicey for possible erasure from callbacks
37-
for (auto ingressStreamIt = wtIngressStreams_.begin();
38-
ingressStreamIt != wtIngressStreams_.end();) {
39-
auto id = ingressStreamIt->first;
40-
auto& stream = ingressStreamIt->second;
41-
ingressStreamIt++;
36+
auto wtIngressStreams = std::move(wtIngressStreams_);
37+
for (auto& [id, stream] : wtIngressStreams) {
4238
// Deliver an error to the application if needed
39+
VLOG(4) << "aborting wt ingress id=" << id << " err=" << errorCode
40+
<< "; open=" << int(stream.open());
4341
if (stream.open()) {
44-
VLOG(4) << "aborting WT ingress id=" << id << " with error=" << errorCode;
4542
stream.deliverReadError(WebTransport::Exception(errorCode, reason));
4643
stopReadingWebTransportIngress(id, errorCode);
47-
} else {
48-
VLOG(4) << "WT ingress already complete for id=" << id;
4944
}
5045
}
51-
wtIngressStreams_.clear();
52-
for (auto egressStreamIt = wtEgressStreams_.begin();
53-
egressStreamIt != wtEgressStreams_.end();) {
54-
auto id = egressStreamIt->first;
55-
auto& stream = egressStreamIt->second;
56-
egressStreamIt++;
46+
47+
auto wtEgressStreams = std::move(wtEgressStreams_);
48+
for (auto& [id, stream] : wtEgressStreams) {
5749
// Deliver an error to the application
5850
stream.onStopSending(errorCode);
59-
// The handler may have run and reset this stream, removing it from
60-
// wtEgressStreams_, otherwise we have to reset it.
61-
if (wtEgressStreams_.find(id) != wtEgressStreams_.end()) {
62-
resetWebTransportEgress(id, errorCode);
63-
}
51+
resetWebTransportEgress(id, errorCode);
6452
}
65-
wtEgressStreams_.clear();
6653
}
6754

6855
void WebTransportImpl::onMaxData(uint64_t maxData) noexcept {

proxygen/lib/http/webtransport/WebTransportImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ class WebTransportImpl : public WebTransport {
109109
~WebTransportImpl() override = default;
110110

111111
void destroy();
112-
void onMaxData(uint64_t maxData) noexcept;
113112

114113
// WT API
115114
folly::Expected<WebTransport::StreamWriteHandle*, WebTransport::ErrorCode>
@@ -379,6 +378,7 @@ class WebTransportImpl : public WebTransport {
379378
sendFlowController_ = FlowController(sendWindow);
380379
recvFlowController_ = FlowController(recvWindow);
381380
}
381+
void onMaxData(uint64_t maxData) noexcept;
382382
};
383383

384384
} // namespace proxygen

0 commit comments

Comments
 (0)