Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Commit

Permalink
Fix logdeviced crash if ServerParams initialization fails. Fixes #133 (
Browse files Browse the repository at this point in the history
…#134)

Summary:
Pull Request resolved: #134

If an exception happens during the initialization of ServerParmeters, we do an ld_critical which invokes bumpErrorCounter that uses the StatsHolder of the server, but the Server is not there anymore so we crash. This case is mostly handled in the destructor of ServerParameters but it doesn't get called because of the exception. This diff does the init logic in an init() function instead of the constructor.

Reviewed By: tau0

Differential Revision: D18138159

fbshipit-source-id: a968e31714717b96dcdf6dc4797961d30180eac8
  • Loading branch information
MohamedBassem authored and facebook-github-bot committed Oct 28, 2019
1 parent b1bf9eb commit 4f3366d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 2 additions & 0 deletions logdevice/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ ServerParameters::ServerParameters(
admin_server_settings_(std::move(admin_server_settings)),
stop_handler_(std::move(stop_handler)) {
ld_check(stop_handler_);
}

void ServerParameters::init() {
// Note: this won't work well if there are multiple Server instances in the
// same process: only one of them will get its error counter bumped. Also,
// there's a data race if the following two lines are run from multiple
Expand Down
3 changes: 3 additions & 0 deletions logdevice/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class ServerParameters {
ServerParameters(const ServerParameters& rhs) = delete;
ServerParameters& operator=(const ServerParameters& rhs) = delete;

// Must be called before passing the params object to the server.
void init();

// Not mutually exclusive.
bool isStorageNode() const;
bool isSequencingEnabled() const;
Expand Down
25 changes: 13 additions & 12 deletions logdevice/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,20 +424,21 @@ int main(int argc, const char** argv) {
ld_info("asserts on (NDEBUG not set)");
}

std::unique_ptr<ServerParameters> params;
auto params = std::make_unique<ServerParameters>(settings_updater,
server_settings,
rebuilding_settings,
locallogstore_settings,
gossip_settings,
settings,
rocksdb_settings,
admin_server_settings,
plugin_registry,
signal_shutdown);
try {
params = std::make_unique<ServerParameters>(settings_updater,
server_settings,
rebuilding_settings,
locallogstore_settings,
gossip_settings,
settings,
rocksdb_settings,
admin_server_settings,
plugin_registry,
signal_shutdown);
params->init();
} catch (const ConstructorFailed&) {
ld_critical("Unable to instantiate ServerParameters. Exiting.");
params.reset();
ld_critical("Unable to initialize ServerParameters. Exiting.");
return 1;
}

Expand Down

0 comments on commit 4f3366d

Please sign in to comment.