Skip to content

Commit 27802f8

Browse files
hanidamlajfacebook-github-bot
authored andcommitted
follow-up for D69196385
Summary: contents of this diff weren't absorbed into D69196385 prior to landing, publishing separately Reviewed By: HsiehYuho Differential Revision: D71130919 fbshipit-source-id: ac947681ef6f0def01f0ca58aa6bda770b0a879d
1 parent 03df8d1 commit 27802f8

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

third-party/proxygen/src/proxygen/lib/http/session/HTTPTransaction.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ void HTTPTransaction::invariantViolation(HTTPException ex) {
650650
}
651651
// In http/1.1, this will send TCP reset and ungracefully terminate the
652652
// connection. In h2, this will send stream reset but keep the connection
653-
// open.
653+
// open. Should this be INTERNAL_ERROR?
654654
sendAbort(ErrorCode::NO_ERROR);
655655
}
656656

third-party/proxygen/src/proxygen/lib/http/session/HTTPTransaction.h

-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ class HTTPTransactionHandler : public TraceEventObserver {
257257
* invoked in cases that violate an internal invariant that is fatal to the
258258
* transaction but can be recoverable for the session or library. One such
259259
* example is mis-use of the egress APIs (sendBody() before sendHeaders()).
260-
*
261260
*/
262261
virtual void onInvariantViolation(const HTTPException& error) noexcept {
263262
LOG(FATAL) << error.what();

third-party/proxygen/src/proxygen/lib/http/session/test/DownstreamTransactionTest.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ TEST_F(DownstreamTransactionTest, InvariantViolationHandler) {
158158
EXPECT_CALL(transport_, sendAbort(_, _));
159159
EXPECT_CALL(handler_, _detachTransaction());
160160
EXPECT_CALL(transport_, detach(&txn));
161+
161162
txn.setHandler(&handler_);
162163
// Send body before headers -- oops;
163164
txn.sendBody(makeBuf(10));

third-party/proxygen/src/proxygen/lib/http/session/test/HTTPDownstreamSessionTest.cpp

+58
Original file line numberDiff line numberDiff line change
@@ -4947,3 +4947,61 @@ TEST_F(HTTP2DownstreamSessionTest, Observer_PreWrite) {
49474947

49484948
expectDetachSession();
49494949
}
4950+
4951+
TEST_F(HTTPDownstreamSessionTest, InvariantViolation) {
4952+
folly::DelayedDestruction::DestructorGuard g(httpSession_);
4953+
4954+
auto handler = addSimpleStrictHandler();
4955+
auto& txn = handler->txn_;
4956+
// attempting to egress body first => invariantViolation
4957+
handler->expectHeaders([&]() { handler->sendBody(100); });
4958+
4959+
EXPECT_CALL(*handler, _onInvariantViolation(_)).WillOnce([&]() {
4960+
// invariantViolation callback can send headers if allowed
4961+
CHECK(txn->canSendHeaders());
4962+
txn->sendHeaders(getResponse(500, 0));
4963+
});
4964+
4965+
sendRequest(getGetRequest(), /*eom=*/true);
4966+
4967+
// this should detach transaction since invariantViolation triggers abort
4968+
EXPECT_CALL(*handler, _detachTransaction);
4969+
flushRequestsAndLoopN(1);
4970+
evbLoopNonBlockN(1);
4971+
4972+
EXPECT_CALL(callbacks_, onHeadersComplete(_, _)).WillOnce([](auto, auto msg) {
4973+
EXPECT_EQ(msg->getStatusCode(), 500);
4974+
});
4975+
4976+
parseOutput(*clientCodec_);
4977+
gracefulShutdown();
4978+
}
4979+
4980+
TEST_F(HTTP2DownstreamSessionTest, InvariantViolation) {
4981+
auto handler = addSimpleStrictHandler();
4982+
auto& txn = handler->txn_;
4983+
// attempting to egress body first => invariantViolation
4984+
handler->expectHeaders([&]() { handler->sendBody(100); });
4985+
4986+
EXPECT_CALL(*handler, _onInvariantViolation(_)).WillOnce([&]() {
4987+
// invariantViolation callback can send headers if allowed
4988+
CHECK(txn->canSendHeaders());
4989+
txn->sendHeaders(getResponse(500, 0));
4990+
txn->sendEOM();
4991+
});
4992+
4993+
sendRequest(getGetRequest(), /*eom=*/true);
4994+
4995+
// this should detach transaction since invariantViolation triggers abort
4996+
EXPECT_CALL(*handler, _detachTransaction);
4997+
flushRequestsAndLoopN(1);
4998+
evbLoopNonBlockN(2);
4999+
5000+
EXPECT_CALL(callbacks_, onHeadersComplete(_, _)).WillOnce([](auto, auto msg) {
5001+
EXPECT_EQ(msg->getStatusCode(), 500);
5002+
});
5003+
EXPECT_CALL(callbacks_, onAbort(_, ErrorCode::NO_ERROR));
5004+
5005+
parseOutput(*clientCodec_);
5006+
gracefulShutdown();
5007+
}

0 commit comments

Comments
 (0)