Skip to content

Commit

Permalink
lspserver: stop connection while the client process died. (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc authored Apr 19, 2024
1 parent 7b339bc commit e45a8e8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lspserver/src/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@
#include "lspserver/Protocol.h"

#include <llvm/ADT/SmallString.h>
#include <llvm/Support/CommandLine.h>

#include <poll.h>
#include <sys/poll.h>
#include <sys/stat.h>

#include <csignal>
#include <cstdint>
#include <cstdio>
#include <memory>
#include <optional>
#include <system_error>

namespace {

llvm::cl::opt<int> ClientProcessID{
"clientProcessId",
llvm::cl::desc(
"Client process ID, if this PID died, the server should exit."),
llvm::cl::init(getppid())};

} // namespace

namespace lspserver {

static llvm::json::Object encodeError(llvm::Error Error) {
Expand Down Expand Up @@ -158,6 +170,11 @@ bool readLine(int fd, const std::atomic<bool> &Close,
Line += Ch;
}
}

if (kill(ClientProcessID, 0) < 0) {
// Parent died.
return false;
}
}
}

Expand Down

0 comments on commit e45a8e8

Please sign in to comment.