Copilot commented on code in PR #8992:
URL: https://github.com/apache/hadoop/pull/8992#discussion_r4567153976
##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java:
##########
@@ -343,6 +344,91 @@ public Object invoke(Object proxy, Method method, Object[]
args)
}
}
+ /**
+ * Once a connection is marked closed, its request sending thread must exit
+ * promptly instead of lingering in rpcRequestQueue.poll() for up to
+ * ipc.client.connection.maxidletime. Under heavy connection churn the
+ * lingering threads used to pile up until the process hit
+ * vm.max_map_count.
+ */
+ @Test
+ @Timeout(value = 60)
+ public void testSendingThreadExitsWhenConnectionClosed() throws Exception {
+ // Long idle time: without the fix the sending thread would linger for
+ // up to this long after the connection is closed.
+ final int maxIdleTimeMs = 60000;
+ final Configuration clientConf = new Configuration(conf);
+ clientConf.setInt(
+ CommonConfigurationKeysPublic.IPC_CLIENT_CONNECTION_MAXIDLETIME_KEY,
+ maxIdleTimeMs);
+
+ final TestServer server = new TestServer(1, false);
+ final CountDownLatch callReceived = new CountDownLatch(1);
+ final CountDownLatch neverReleased = new CountDownLatch(1);
+ // Keep a call in flight so the client reader is blocked on the socket
+ // and observes the close immediately when the server goes away.
+ server.callListener = () -> {
+ callReceived.countDown();
+ // server.stop() interrupts the handler thread. Keep blocking until the
+ // test releases neverReleased so the call stays in flight while the
+ // connection is closed. Otherwise the handler could race the connection
+ // close and send a successful echo response before markClosed() runs,
+ // which would leave the sending thread alive in rpcRequestQueue.poll().
+ boolean released = false;
+ while (!released) {
+ try {
+ neverReleased.await();
+ released = true;
+ } catch (InterruptedException ignored) {
+ // keep waiting; the interrupt flag is cleared by await()
+ }
+ }
+ };
+ final InetSocketAddress addr = NetUtils.getConnectAddress(server);
+ server.start();
+
+ final String senderName = "IPC Parameter Sending Thread for " + addr;
+ final Client client = new Client(LongWritable.class, clientConf);
+ final AtomicBoolean callFailed = new AtomicBoolean(false);
+ final Thread caller = new Thread(() -> {
+ try {
+ call(client, RANDOM.nextLong(), addr, clientConf);
+ } catch (IOException expected) {
+ // The server is stopped while the call is in flight.
+ callFailed.set(true);
+ }
+ });
+ try {
+ caller.start();
+ assertTrue(callReceived.await(10, TimeUnit.SECONDS), "server never
received the call");
Review Comment:
If an assertion fails before the `caller.join(10000)` line is reached (e.g.,
`callReceived.await(...)` times out), the test can exit the main path without
ever joining `caller`. Even though `client.stop()` is invoked in `finally`,
leaving the non-daemon `caller` unjoined can create intermittent suite hangs or
noisy thread leaks in CI. Consider moving the join/termination logic into
`finally` (optionally interrupting the caller first) or creating the caller as
a daemon thread and still joining it best-effort in `finally`.
##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java:
##########
@@ -343,6 +344,91 @@ public Object invoke(Object proxy, Method method, Object[]
args)
}
}
+ /**
+ * Once a connection is marked closed, its request sending thread must exit
+ * promptly instead of lingering in rpcRequestQueue.poll() for up to
+ * ipc.client.connection.maxidletime. Under heavy connection churn the
+ * lingering threads used to pile up until the process hit
+ * vm.max_map_count.
+ */
+ @Test
+ @Timeout(value = 60)
+ public void testSendingThreadExitsWhenConnectionClosed() throws Exception {
+ // Long idle time: without the fix the sending thread would linger for
+ // up to this long after the connection is closed.
+ final int maxIdleTimeMs = 60000;
+ final Configuration clientConf = new Configuration(conf);
+ clientConf.setInt(
+ CommonConfigurationKeysPublic.IPC_CLIENT_CONNECTION_MAXIDLETIME_KEY,
+ maxIdleTimeMs);
+
+ final TestServer server = new TestServer(1, false);
+ final CountDownLatch callReceived = new CountDownLatch(1);
+ final CountDownLatch neverReleased = new CountDownLatch(1);
+ // Keep a call in flight so the client reader is blocked on the socket
+ // and observes the close immediately when the server goes away.
+ server.callListener = () -> {
+ callReceived.countDown();
+ // server.stop() interrupts the handler thread. Keep blocking until the
+ // test releases neverReleased so the call stays in flight while the
+ // connection is closed. Otherwise the handler could race the connection
+ // close and send a successful echo response before markClosed() runs,
+ // which would leave the sending thread alive in rpcRequestQueue.poll().
+ boolean released = false;
+ while (!released) {
+ try {
+ neverReleased.await();
+ released = true;
+ } catch (InterruptedException ignored) {
+ // keep waiting; the interrupt flag is cleared by await()
+ }
+ }
+ };
+ final InetSocketAddress addr = NetUtils.getConnectAddress(server);
+ server.start();
+
+ final String senderName = "IPC Parameter Sending Thread for " + addr;
+ final Client client = new Client(LongWritable.class, clientConf);
+ final AtomicBoolean callFailed = new AtomicBoolean(false);
+ final Thread caller = new Thread(() -> {
+ try {
+ call(client, RANDOM.nextLong(), addr, clientConf);
+ } catch (IOException expected) {
+ // The server is stopped while the call is in flight.
+ callFailed.set(true);
+ }
+ });
+ try {
+ caller.start();
+ assertTrue(callReceived.await(10, TimeUnit.SECONDS), "server never
received the call");
+ assertTrue(countThreadsNamed(senderName) > 0, "sending thread should
exist while connected");
Review Comment:
This assertion is potentially racy and can lead to test flakiness: the
server receiving the call doesn’t guarantee the client’s parameter-sending
thread has been created and is visible via `Thread.getAllStackTraces()` at that
exact instant. Consider waiting (with a bounded timeout) until
`countThreadsNamed(senderName) > 0` instead of asserting immediately (e.g.,
using `GenericTestUtils.waitFor`).
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]