bneradt commented on code in PR #13329:
URL: https://github.com/apache/trafficserver/pull/13329#discussion_r3477459223


##########
src/mgmt/rpc/server/unit_tests/test_rpcserver.cc:
##########
@@ -344,6 +351,57 @@ send_request(std::string json, std::promise<std::string> p)
   auto              resp = rpc_client.query(json);
   p.set_value(resp);
 }
+
+TEST_CASE("IPCSocketClient write returns when the peer stops reading", 
"[socket][client]")
+{
+  int fds[2];
+  REQUIRE(::socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0);
+
+  int const flags = ::fcntl(fds[0], F_GETFL, 0);
+  REQUIRE(flags >= 0);
+  REQUIRE(::fcntl(fds[0], F_SETFL, flags | O_NONBLOCK) == 0);
+
+  std::vector<char> fill(4096, 'x');
+  while (true) {
+    ssize_t const ret = ::write(fds[0], fill.data(), fill.size());
+    if (ret < 0) {
+      REQUIRE((errno == EAGAIN || errno == EWOULDBLOCK));
+      break;
+    }
+    REQUIRE(ret > 0);
+  }
+
+  TestableIPCSocketClient rpc_client;
+  pid_t const             pid = ::fork();
+  REQUIRE(pid >= 0);
+  if (pid == 0) {
+    ::close(fds[1]);
+    char const byte = 'x';
+    auto const ret  = rpc_client._safe_write(fds[0], &byte, 1);
+    ::close(fds[0]);
+    _exit(ret == -1 ? 0 : 1);
+  }
+
+  int status = 0;
+  for (int i = 0; i < 20; ++i) {
+    if (::waitpid(pid, &status, WNOHANG) == pid) {
+      break;
+    }
+    std::this_thread::sleep_for(std::chrono::milliseconds(100));
+  }
+
+  if (::waitpid(pid, &status, WNOHANG) == 0) {
+    ::kill(pid, SIGKILL);
+    ::waitpid(pid, &status, 0);
+    FAIL("_safe_write did not return when the nonblocking socket stayed 
unwritable");
+  }

Review Comment:
   Fixed in fb13f27906. The test now waits for the child with a steady_clock 
deadline of 10 seconds and only kills/reaps it after that deadline, instead of 
using the fixed 20 x 100ms polling loop.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to