[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
This commit is contained in:
Kadir Cetinkaya 2021-02-22 09:49:08 +01:00
parent ad9091c5fa
commit 1a5dfb7db2
No known key found for this signature in database
GPG Key ID: E39E36B8D2057ED6
1 changed files with 7 additions and 0 deletions

View File

@ -80,6 +80,11 @@ llvm::cl::opt<std::string> ServerAddress(
"server-address", llvm::cl::init("0.0.0.0:50051"), "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::desc("Address of the invoked server. Defaults to 0.0.0.0:50051"));
llvm::cl::opt<size_t> 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<grpc::ServerContext *> CurrentRequest; static Key<grpc::ServerContext *> CurrentRequest;
class RemoteIndexServer final : public v1::SymbolIndex::Service { class RemoteIndexServer final : public v1::SymbolIndex::Service {
@ -311,6 +316,8 @@ void runServerAndWait(clangd::SymbolIndex &Index, llvm::StringRef ServerAddress,
grpc::ServerBuilder Builder; grpc::ServerBuilder Builder;
Builder.AddListeningPort(ServerAddress.str(), Builder.AddListeningPort(ServerAddress.str(),
grpc::InsecureServerCredentials()); grpc::InsecureServerCredentials());
Builder.AddChannelArgument(GRPC_ARG_MAX_CONNECTION_IDLE_MS,
IdleTimeoutSeconds * 1000);
Builder.RegisterService(&Service); Builder.RegisterService(&Service);
std::unique_ptr<grpc::Server> Server(Builder.BuildAndStart()); std::unique_ptr<grpc::Server> Server(Builder.BuildAndStart());
log("Server listening on {0}", ServerAddress); log("Server listening on {0}", ServerAddress);