From 268b540edae0b3e51d033795a4dd7404a5756a93 Mon Sep 17 00:00:00 2001
From: Masaori Koshiba <masaori@apache.org>
Date: Thu, 28 Oct 2021 01:53:14 +0900
Subject: [PATCH] Ignore ECONNABORTED on blocking accept (#8453)

---
 iocore/net/P_UnixNet.h      |  4 +++-
 iocore/net/UnixNetAccept.cc | 30 ++++++++++++++++++++----------
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/iocore/net/P_UnixNet.h b/iocore/net/P_UnixNet.h
index 0043e1d763c..cff9439e9a4 100644
--- a/iocore/net/P_UnixNet.h
+++ b/iocore/net/P_UnixNet.h
@@ -480,6 +480,7 @@ change_net_connections_throttle(const char *token, RecDataT data_type, RecData v
   return 0;
 }
 
+// 2  - ignore
 // 1  - transient
 // 0  - report as warning
 // -1 - fatal
@@ -487,8 +488,9 @@ TS_INLINE int
 accept_error_seriousness(int res)
 {
   switch (res) {
-  case -EAGAIN:
   case -ECONNABORTED:
+    return 2;
+  case -EAGAIN:
   case -ECONNRESET: // for Linux
   case -EPIPE:      // also for Linux
     return 1;
diff --git a/iocore/net/UnixNetAccept.cc b/iocore/net/UnixNetAccept.cc
index d1ecc22d185..1ce5923b8ff 100644
--- a/iocore/net/UnixNetAccept.cc
+++ b/iocore/net/UnixNetAccept.cc
@@ -295,19 +295,29 @@ NetAccept::do_blocking_accept(EThread *t)
   do {
     if ((res = server.accept(&con)) < 0) {
       int seriousness = accept_error_seriousness(res);
-      if (seriousness >= 0) { // not so bad
-        if (!seriousness) {   // bad enough to warn about
-          check_transient_accept_error(res);
-        }
+      switch (seriousness) {
+      case 0:
+        // bad enough to warn about
+        check_transient_accept_error(res);
         safe_delay(net_throttle_delay);
         return 0;
+      case 1:
+        // not so bad but needs delay
+        safe_delay(net_throttle_delay);
+        return 0;
+      case 2:
+        // ignore
+        return 0;
+      case -1:
+        [[fallthrough]];
+      default:
+        if (!action_->cancelled) {
+          SCOPED_MUTEX_LOCK(lock, action_->mutex ? action_->mutex : t->mutex, t);
+          action_->continuation->handleEvent(EVENT_ERROR, (void *)static_cast<intptr_t>(res));
+          Warning("accept thread received fatal error: errno = %d", errno);
+        }
+        return -1;
       }
-      if (!action_->cancelled) {
-        SCOPED_MUTEX_LOCK(lock, action_->mutex ? action_->mutex : t->mutex, t);
-        action_->continuation->handleEvent(EVENT_ERROR, (void *)static_cast<intptr_t>(res));
-        Warning("accept thread received fatal error: errno = %d", errno);
-      }
-      return -1;
     }
     // check for throttle
     if (!opt.backdoor && check_net_throttle(ACCEPT)) {
