diff --git a/third-party/fizz/src/fizz/client/ClientProtocol.cpp b/third-party/fizz/src/fizz/client/ClientProtocol.cpp index 4fd11e977c3322..df7669ae1ec76d 100644 --- a/third-party/fizz/src/fizz/client/ClientProtocol.cpp +++ b/third-party/fizz/src/fizz/client/ClientProtocol.cpp @@ -286,15 +286,22 @@ Actions handleError( newState.writeRecordLayer() = nullptr; newState.readRecordLayer() = nullptr; }); + + Actions actions; + actions.emplace_back(std::move(transition)); + if (alertDesc && state.writeRecordLayer()) { - Alert alert(*alertDesc); - WriteToSocket write; - write.contents.emplace_back( - state.writeRecordLayer()->writeAlert(std::move(alert))); - return actions(std::move(transition), std::move(write), std::move(error)); - } else { - return actions(std::move(transition), std::move(error)); + try { + Alert alert(*alertDesc); + WriteToSocket write; + write.contents.emplace_back( + state.writeRecordLayer()->writeAlert(std::move(alert))); + actions.emplace_back(std::move(write)); + } catch (...) { + } } + actions.emplace_back(std::move(error)); + return actions; } Actions handleAppCloseImmediate(const State& state) { diff --git a/third-party/fizz/src/fizz/client/test/ClientProtocolTest.cpp b/third-party/fizz/src/fizz/client/test/ClientProtocolTest.cpp index d9baf56ac91c94..012f6b0e89a328 100644 --- a/third-party/fizz/src/fizz/client/test/ClientProtocolTest.cpp +++ b/third-party/fizz/src/fizz/client/test/ClientProtocolTest.cpp @@ -5918,6 +5918,20 @@ TEST_F(ClientProtocolTest, TestPskWithoutCerts) { EXPECT_EQ(state_.clientAuthRequested().value(), ClientAuthType::NotRequested); } +TEST_F(ClientProtocolTest, HandleErrorDoesntThrow) { + setupAcceptingData(); + EXPECT_CALL(*mockWrite_, _write(_, _)) + .WillOnce(Throw(std::runtime_error("write error"))); + + ReportError error("some error"); + AlertDescription ad = AlertDescription::internal_error; + + auto shouldNotThrow = [&] { + auto actions = detail::handleError(state_, std::move(error), ad); + expectActions(actions); + }; + EXPECT_NO_THROW(shouldNotThrow()); +} } // namespace test } // namespace client } // namespace fizz diff --git a/third-party/fizz/src/fizz/server/ServerProtocol.cpp b/third-party/fizz/src/fizz/server/ServerProtocol.cpp index 66e0600886baec..ccf121724269d9 100644 --- a/third-party/fizz/src/fizz/server/ServerProtocol.cpp +++ b/third-party/fizz/src/fizz/server/ServerProtocol.cpp @@ -286,15 +286,22 @@ Actions handleError( newState.writeRecordLayer() = nullptr; newState.readRecordLayer() = nullptr; }); + + Actions actions; + actions.emplace_back(std::move(transition)); + if (alertDesc && state.writeRecordLayer()) { - Alert alert(*alertDesc); - WriteToSocket write; - write.contents.emplace_back( - state.writeRecordLayer()->writeAlert(std::move(alert))); - return actions(std::move(transition), std::move(write), std::move(error)); - } else { - return actions(std::move(transition), std::move(error)); + try { + Alert alert(*alertDesc); + WriteToSocket write; + write.contents.emplace_back( + state.writeRecordLayer()->writeAlert(std::move(alert))); + actions.emplace_back(std::move(write)); + } catch (...) { + } } + actions.emplace_back(std::move(error)); + return actions; } Actions handleAppCloseImmediate(const State& state) { diff --git a/third-party/fizz/src/fizz/server/test/ServerProtocolTest.cpp b/third-party/fizz/src/fizz/server/test/ServerProtocolTest.cpp index cb3474f5c2b7b3..1d0fb9ce660d13 100644 --- a/third-party/fizz/src/fizz/server/test/ServerProtocolTest.cpp +++ b/third-party/fizz/src/fizz/server/test/ServerProtocolTest.cpp @@ -6743,6 +6743,21 @@ TEST_F(ServerProtocolTest, AsyncKeyExchangeTest) { EXPECT_TRUE( std::all_of(begin(cr), end(cr), [](auto c) { return c == 0x44; })); } + +TEST_F(ServerProtocolTest, HandleErrorDoesntThrow) { + setUpAcceptingData(); + EXPECT_CALL(*appWrite_, _write(_, _)) + .WillOnce(Throw(std::runtime_error("write error"))); + + ReportError error("some error"); + AlertDescription ad = AlertDescription::internal_error; + + auto shouldNotThrow = [&] { + auto actions = detail::handleError(state_, std::move(error), ad); + expectActions(actions); + }; + EXPECT_NO_THROW(shouldNotThrow()); +} } // namespace test } // namespace server } // namespace fizz