[clang-tools-extra] 22a3e40 - [clangd] Set gRPC deadlines to all remote index requests

Kirill Bobyrev via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 1 03:46:40 PDT 2020


Author: Kirill Bobyrev
Date: 2020-07-01T12:46:29+02:00
New Revision: 22a3e4055f4382e8ebbf67705501e6969c6b398b

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

LOG: [clangd] Set gRPC deadlines to all remote index requests

Summary: "TL;DR: Always set a deadline.", https://grpc.io/blog/deadlines/

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82844

Added: 
    

Modified: 
    clang-tools-extra/clangd/index/remote/Client.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/index/remote/Client.cpp b/clang-tools-extra/clangd/index/remote/Client.cpp
index 366a37a135a4..c43afd2573a9 100644
--- a/clang-tools-extra/clangd/index/remote/Client.cpp
+++ b/clang-tools-extra/clangd/index/remote/Client.cpp
@@ -15,6 +15,8 @@
 #include "support/Logger.h"
 #include "support/Trace.h"
 
+#include <chrono>
+
 namespace clang {
 namespace clangd {
 namespace remote {
@@ -25,7 +27,6 @@ class IndexClient : public clangd::SymbolIndex {
   using StreamingCall = std::unique_ptr<grpc::ClientReader<ReplyT>> (
       remote::SymbolIndex::Stub::*)(grpc::ClientContext *, const RequestT &);
 
-  // FIXME(kirillbobyrev): Set deadlines for requests.
   template <typename RequestT, typename ReplyT, typename ClangdRequestT,
             typename CallbackT>
   bool streamRPC(ClangdRequestT Request,
@@ -35,6 +36,9 @@ class IndexClient : public clangd::SymbolIndex {
     trace::Span Tracer(RequestT::descriptor()->name());
     const auto RPCRequest = toProtobuf(Request);
     grpc::ClientContext Context;
+    std::chrono::system_clock::time_point Deadline =
+        std::chrono::system_clock::now() + DeadlineWaitingTime;
+    Context.set_deadline(Deadline);
     auto Reader = (Stub.get()->*RPCCall)(&Context, RPCRequest);
     llvm::BumpPtrAllocator Arena;
     llvm::UniqueStringSaver Strings(Arena);
@@ -54,8 +58,11 @@ class IndexClient : public clangd::SymbolIndex {
   }
 
 public:
-  IndexClient(std::shared_ptr<grpc::Channel> Channel)
-      : Stub(remote::SymbolIndex::NewStub(Channel)) {}
+  IndexClient(
+      std::shared_ptr<grpc::Channel> Channel,
+      std::chrono::milliseconds DeadlineTime = std::chrono::milliseconds(1000))
+      : Stub(remote::SymbolIndex::NewStub(Channel)),
+        DeadlineWaitingTime(DeadlineTime) {}
 
   void lookup(const clangd::LookupRequest &Request,
               llvm::function_ref<void(const clangd::Symbol &)> Callback) const {
@@ -84,6 +91,8 @@ class IndexClient : public clangd::SymbolIndex {
 
 private:
   std::unique_ptr<remote::SymbolIndex::Stub> Stub;
+  // Each request will be terminated if it takes too long.
+  std::chrono::milliseconds DeadlineWaitingTime;
 };
 
 } // namespace


        


More information about the cfe-commits mailing list