diff options
author | Kadir Cetinkaya <kadircet@google.com> | 2019-10-09 13:59:31 +0000 |
---|---|---|
committer | Kadir Cetinkaya <kadircet@google.com> | 2019-10-09 13:59:31 +0000 |
commit | 9a3a87d189753b7cea14d109c012ba37671e4adf (patch) | |
tree | 597609aa9623b4109b1d41d814d8f09ebf975494 | |
parent | 2ae54aba03f24bf5047bd0fc4552c4bd7a09a39a (diff) | |
download | bcm5719-llvm-9a3a87d189753b7cea14d109c012ba37671e4adf.tar.gz bcm5719-llvm-9a3a87d189753b7cea14d109c012ba37671e4adf.zip |
[clangd] Make sure ReplyCallbacks are destroyed before RequestCancelersMutex
Summary:
After rL374163, replycallbacks might have a cancellable context, which
will try to access RequestCancellers on destruction. See
http://45.33.8.238/mac/1245/step_7.txt for a sample failure.
Reviewers: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits, thakis
Tags: #clang
Differential Revision: https://reviews.llvm.org/D68702
llvm-svn: 374168
-rw-r--r-- | clang-tools-extra/clangd/ClangdLSPServer.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index ea151762659..4dc3412538a 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -371,16 +371,6 @@ private: llvm::StringMap<std::function<void(llvm::json::Value)>> Notifications; llvm::StringMap<std::function<void(llvm::json::Value, ReplyOnce)>> Calls; - // The maximum number of callbacks held in clangd. - // - // We bound the maximum size to the pending map to prevent memory leakage - // for cases where LSP clients don't reply for the request. - static constexpr int MaxReplayCallbacks = 100; - mutable std::mutex CallMutex; - int NextCallID = 0; /* GUARDED_BY(CallMutex) */ - std::deque<std::pair</*RequestID*/ int, - /*ReplyHandler*/ Callback<llvm::json::Value>>> - ReplyCallbacks; /* GUARDED_BY(CallMutex) */ // Method calls may be cancelled by ID, so keep track of their state. // This needs a mutex: handlers may finish on a different thread, and that's @@ -432,6 +422,19 @@ private: })); } + // The maximum number of callbacks held in clangd. + // + // We bound the maximum size to the pending map to prevent memory leakage + // for cases where LSP clients don't reply for the request. + // This has to go after RequestCancellers and RequestCancellersMutex since it + // can contain a callback that has a cancelable context. + static constexpr int MaxReplayCallbacks = 100; + mutable std::mutex CallMutex; + int NextCallID = 0; /* GUARDED_BY(CallMutex) */ + std::deque<std::pair</*RequestID*/ int, + /*ReplyHandler*/ Callback<llvm::json::Value>>> + ReplyCallbacks; /* GUARDED_BY(CallMutex) */ + ClangdLSPServer &Server; }; constexpr int ClangdLSPServer::MessageHandler::MaxReplayCallbacks; |