Internal change

PiperOrigin-RevId: 360794882
This commit is contained in:
hai007
2021-03-03 17:31:17 -08:00
committed by Copybara-Service
parent 891df74532
commit c5e8f134f6
2 changed files with 21 additions and 0 deletions
+12
View File
@@ -81,6 +81,18 @@ void EndpointManager::EndpointChannelLoopRunnable(
if (!keep_using_channel.ok()) {
Exception exception = keep_using_channel.GetException();
// An "invalid proto" may be a final payload on a channel we're about to
// close, so we'll loop back around once. We set |last_failed_medium| to
// ensure we don't loop indefinitely. See crbug.com/1182031 for more
// detail.
if (exception.Raised(Exception::kInvalidProtocolBuffer)) {
last_failed_medium = channel->GetMedium();
NEARBY_LOG(INFO,
"Received invalid protobuf message, re-fetching endpoint "
"channel; last_failed_medium=%d",
last_failed_medium);
continue;
}
if (exception.Raised(Exception::kIo)) {
last_failed_medium = channel->GetMedium();
NEARBY_LOG(INFO, "Endpoint channel IO exception; last_failed_medium=%d",
@@ -253,6 +253,15 @@ TEST_F(EndpointManagerTest, SendControlMessageWorks) {
NEARBY_LOG(INFO, "Will call destructors now");
}
TEST_F(EndpointManagerTest, SingleReadOnInvalidPayload) {
auto endpoint_channel = std::make_unique<MockEndpointChannel>();
EXPECT_CALL(*endpoint_channel, Read())
.WillOnce(
Return(ExceptionOr<ByteArray>(Exception::kInvalidProtocolBuffer)));
EXPECT_CALL(*endpoint_channel, Close(_)).Times(1);
RegisterEndpoint(std::move(endpoint_channel));
}
} // namespace
} // namespace connections
} // namespace nearby