[clang-tools-extra] f764a1a - [clangd] Avoid possible crash: apply configuration after binding methods

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 19 16:13:49 PST 2021


Author: Sam McCall
Date: 2021-11-20T01:13:38+01:00
New Revision: f764a1a5bd7c281d3d7cc3c6d7f1430711176762

URL: https://github.com/llvm/llvm-project/commit/f764a1a5bd7c281d3d7cc3c6d7f1430711176762
DIFF: https://github.com/llvm/llvm-project/commit/f764a1a5bd7c281d3d7cc3c6d7f1430711176762.diff

LOG: [clangd] Avoid possible crash: apply configuration after binding methods

The configuration may kick off indexing, which may involve sending LSP
messages.
The crash is fiddly to reproduce in a hermetic test (we need background
indexing on without disk storage, and to handle server->client messages
in LSPClient...)

Fixes https://github.com/clangd/clangd/issues/926

Added: 
    

Modified: 
    clang-tools-extra/clangd/ClangdLSPServer.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 6c000d3290fda..762ca1aa213a4 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -493,7 +493,6 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
     Server.emplace(*CDB, TFS, Opts,
                    static_cast<ClangdServer::Callbacks *>(this));
   }
-  applyConfiguration(Params.initializationOptions.ConfigSettings);
 
   Opts.CodeComplete.EnableSnippets = Params.capabilities.CompletionSnippets;
   Opts.CodeComplete.IncludeFixIts = Params.capabilities.CompletionFixes;
@@ -627,6 +626,10 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
   if (Opts.Encoding)
     Result["offsetEncoding"] = *Opts.Encoding;
   Reply(std::move(Result));
+
+  // Apply settings after we're fully initialized.
+  // This can start background indexing and in turn trigger LSP notifications.
+  applyConfiguration(Params.initializationOptions.ConfigSettings);
 }
 
 void ClangdLSPServer::onInitialized(const InitializedParams &Params) {}


        


More information about the cfe-commits mailing list