Skip to content

Commit

Permalink
nixd/Server/Controller: fix potential data race while reading config (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc authored Jul 30, 2023
2 parents 239d8d9 + 7b19dd7 commit e56a7c2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions nixd/lib/Server/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,12 @@ void Controller::onDocumentDidClose(
void Controller::onDecalration(
const lspserver::TextDocumentPositionParams &Params,
lspserver::Callback<llvm::json::Value> Reply) {
if (!Config.options.enable) {
bool EnableOption;
{
std::lock_guard _(ConfigLock);
EnableOption = Config.options.enable;
}
if (!EnableOption) {
Reply(nullptr);
return;
}
Expand Down Expand Up @@ -735,9 +740,17 @@ void Controller::onFormat(
this]() -> std::optional<std::string> {
try {
namespace bp = boost::process;

bp::opstream To;
bp::ipstream From;
bp::child Fmt(Config.formatting.command, bp::std_out > From,

std::string FormatCommand;
{
std::lock_guard _(ConfigLock);
FormatCommand = Config.formatting.command;
}

bp::child Fmt(std::move(FormatCommand), bp::std_out > From,
bp::std_in < To);

To << Code;
Expand Down

0 comments on commit e56a7c2

Please sign in to comment.