From: Sam McCall Date: Sat, 20 Nov 2021 00:10:30 +0000 (+0100) Subject: [clangd] Avoid possible crash: apply configuration after binding methods X-Git-Tag: upstream/15.0.7~25173 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f764a1a5bd7c281d3d7cc3c6d7f1430711176762;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index 6c000d3..762ca1a 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(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) {}