[PATCH] D110615: [ORC] SimpleRemoteEPCServer: exit gracefully when detecting invalid connection

Stefan Gränitz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 28 02:25:53 PDT 2021


sgraenitz created this revision.
sgraenitz added a reviewer: lhames.
sgraenitz requested review of this revision.
Herald added a project: LLVM.

In case of invalid connectivity settings, EPC transport's `listenLoop()` thread may tear down the server. In this case, the main thread won't reach the `waitForDisconnect()` in the main function and instead exit via `ExitOnErr` before. The server's `ShutdownErr` member will still hold an unchecked error, which causes an abnormal shutdown:

  SimpleRemoteEPCServer::sendMessage: opc = Setup, seqno = 0, tag-addr = 0x0, arg-buffer = 0x48c bytes
    \--> SimpleRemoteEPC::sendMessage failed
  Program aborted due to an unhandled Error:
  Bad file descriptor

Call-stack of the main thread:

  abort()
  llvm::Error::fatalUncheckedError() const
  llvm::Error::assertIsChecked()
  llvm::Error::~Error()
  llvm::orc::SimpleRemoteEPCServer::~SimpleRemoteEPCServer()
  ...
  llvm::Expected<...> llvm::orc::SimpleRemoteEPCServer::Create<...>(...)
  main

With this patch applied, the server will shutdown gracefully:

  SimpleRemoteEPCServer::sendMessage: opc = Setup, seqno = 0, tag-addr = 0x0, arg-buffer = 0x48c bytes
    \--> SimpleRemoteEPC::sendMessage failed
  SimpleRemoteEPCServer: Bad file descriptor
  llvm-jitlink-executor: Bad file descriptor

The duplicate error message appears to be originating from the two threads involved.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110615

Files:
  llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.h


Index: llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.h
===================================================================
--- llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.h
+++ llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.h
@@ -95,7 +95,8 @@
     // process fails.
     if (!Server->ReportError)
       Server->ReportError = [](Error Err) {
-        logAllUnhandledErrors(std::move(Err), errs(), "SimpleRemoteEPCServer ");
+        logAllUnhandledErrors(std::move(Err), errs(),
+                              "SimpleRemoteEPCServer: ");
       };
 
     // Attempt to create transport.
@@ -137,6 +138,11 @@
 
   void handleDisconnect(Error Err) override;
 
+  ~SimpleRemoteEPCServer() override {
+    if (Error Err = waitForDisconnect())
+      ReportError(std::move(Err));
+  }
+
 private:
   Error sendMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo,
                     ExecutorAddr TagAddr, ArrayRef<char> ArgBytes);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110615.375502.patch
Type: text/x-patch
Size: 1011 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210928/f13e9062/attachment.bin>


More information about the llvm-commits mailing list