From 1a5dfb7db23e3c0aec0b4356a60b9d6b7c8f9683 Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya Date: Mon, 22 Feb 2021 09:49:08 +0100 Subject: [PATCH] [clangd][remote] Add flag to set idletimeout By default gRPC has no idletimeout and some firewalls might drop idle connections after a certain period. This results in idle clients shouting into void until server resets the connection. Differential Revision: https://reviews.llvm.org/D97536 --- clang-tools-extra/clangd/index/remote/server/Server.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp b/clang-tools-extra/clangd/index/remote/server/Server.cpp index 20b140e00787..3de2c38f7c08 100644 --- a/clang-tools-extra/clangd/index/remote/server/Server.cpp +++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp @@ -80,6 +80,11 @@ llvm::cl::opt ServerAddress( "server-address", llvm::cl::init("0.0.0.0:50051"), llvm::cl::desc("Address of the invoked server. Defaults to 0.0.0.0:50051")); +llvm::cl::opt IdleTimeoutSeconds( + "idle-timeout", llvm::cl::init(8 * 60), + llvm::cl::desc("Maximum time a channel may stay idle until server closes " + "the connection, in seconds. Defaults to 480.")); + static Key CurrentRequest; class RemoteIndexServer final : public v1::SymbolIndex::Service { @@ -311,6 +316,8 @@ void runServerAndWait(clangd::SymbolIndex &Index, llvm::StringRef ServerAddress, grpc::ServerBuilder Builder; Builder.AddListeningPort(ServerAddress.str(), grpc::InsecureServerCredentials()); + Builder.AddChannelArgument(GRPC_ARG_MAX_CONNECTION_IDLE_MS, + IdleTimeoutSeconds * 1000); Builder.RegisterService(&Service); std::unique_ptr Server(Builder.BuildAndStart()); log("Server listening on {0}", ServerAddress);