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

Kirill Bobyrev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 1 04:17:35 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG22a3e4055f43: [clangd] Set gRPC deadlines to all remote index requests (authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82844/new/

https://reviews.llvm.org/D82844

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


Index: clang-tools-extra/clangd/index/remote/Client.cpp
===================================================================
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ 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 @@
   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 @@
     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 @@
   }
 
 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 @@
 
 private:
   std::unique_ptr<remote::SymbolIndex::Stub> Stub;
+  // Each request will be terminated if it takes too long.
+  std::chrono::milliseconds DeadlineWaitingTime;
 };
 
 } // namespace


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82844.274751.patch
Type: text/x-patch
Size: 1963 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200701/27ff1234/attachment.bin>


More information about the cfe-commits mailing list