Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion source/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ InstanceImpl::InstanceImpl(Options& options, Network::Address::InstanceConstShar
} catch (const EnvoyException& e) {
ENVOY_LOG(critical, "error initializing configuration '{}': {}", options.configPath(),
e.what());

terminate();
throw;
} catch (const std::exception& e) {
ENVOY_LOG(critical, "error initializing due to unexpected exception: {}", e.what());
terminate();
throw;
} catch (...) {
ENVOY_LOG(critical, "error initializing due to unknown exception");
terminate();
throw;
}
Expand Down
29 changes: 29 additions & 0 deletions test/server/server_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using testing::HasSubstr;
using testing::InSequence;
using testing::Invoke;
using testing::InvokeWithoutArgs;
using testing::Property;
using testing::Ref;
using testing::SaveArg;
Expand Down Expand Up @@ -299,5 +300,33 @@ TEST_P(ServerInstanceImplTest, NoOptionsPassed) {
EnvoyException, "unable to read file: ");
}

// Validate that when std::exception is unexpectedly thrown, we exit safely.
// This is a regression test for when we used to crash.
TEST_P(ServerInstanceImplTest, StdExceptionThrowInConstructor) {
EXPECT_CALL(restart_, initialize(_, _)).WillOnce(InvokeWithoutArgs([] {
throw(std::runtime_error("foobar"));
}));
EXPECT_THROW_WITH_MESSAGE(initialize("test/server/node_bootstrap.yaml"), std::runtime_error,
"foobar");
}

// Neither EnvoyException nor std::exception derived.
class FakeException {
public:
FakeException(const std::string& what) : what_(what) {}
const std::string& what() const { return what_; }

const std::string what_;
};

// Validate that when a totally unknown exception is unexpectedly thrown, we
// exit safely. This is a regression test for when we used to crash.
TEST_P(ServerInstanceImplTest, UnknownExceptionThrowInConstructor) {
EXPECT_CALL(restart_, initialize(_, _)).WillOnce(InvokeWithoutArgs([] {
throw(FakeException("foobar"));
}));
EXPECT_THROW_WITH_MESSAGE(initialize("test/server/node_bootstrap.yaml"), FakeException, "foobar");
}

} // namespace Server
} // namespace Envoy