You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2022/04/21 04:23:56 UTC

[GitHub] [zookeeper] polaris-alioth opened a new pull request, #1864: fix: Thread leaks occur when dns fails.

polaris-alioth opened a new pull request, #1864:
URL: https://github.com/apache/zookeeper/pull/1864

   Fix : https://issues.apache.org/jira/browse/ZOOKEEPER-4525
   
   ### Description
   NullPointExcption has bees thrown when call Zookeeper::close. EventThread cannot be closed.
   
   ### Motivation and Context
   NullPointExcption has bees thrown when call Zookeeper::close. EventThread cannot be closed.
   
   ### How to test this PR?
   use unknown address and call Zookeeper::close, the state of EventThread will change to TERMINATED
   


-- 
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: notifications-unsubscribe@zookeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [zookeeper] polaris-alioth commented on a diff in pull request #1864: fix: Thread leaks occur when dns fails.

Posted by GitBox <gi...@apache.org>.
polaris-alioth commented on code in PR #1864:
URL: https://github.com/apache/zookeeper/pull/1864#discussion_r857078115


##########
zookeeper-server/src/test/java/org/apache/zookeeper/ClientCloseTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper;
+
+import org.apache.zookeeper.client.ZKClientConfig;
+import org.apache.zookeeper.server.ServerCnxnFactory;
+import org.apache.zookeeper.server.ZooKeeperThread;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+
+public class ClientCloseTest extends ZKTestCase {
+
+    @BeforeClass
+    public static void setupClass() {
+        System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
+        System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty");
+    }
+
+    @Test
+    public void testClientClose() {
+        ZooKeeperThread sendThread = null;
+        ZooKeeperThread eventThread = null;
+        try {

Review Comment:
   I agree with you. It's a good way for the UT.



-- 
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: notifications-unsubscribe@zookeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [zookeeper] polaris-alioth commented on a diff in pull request #1864: fix: Thread leaks occur when dns fails.

Posted by GitBox <gi...@apache.org>.
polaris-alioth commented on code in PR #1864:
URL: https://github.com/apache/zookeeper/pull/1864#discussion_r858431536


##########
zookeeper-server/src/test/java/org/apache/zookeeper/ClientCloseTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper;
+
+import org.apache.zookeeper.client.ZKClientConfig;
+import org.apache.zookeeper.server.ServerCnxnFactory;
+import org.apache.zookeeper.server.ZooKeeperThread;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+
+public class ClientCloseTest extends ZKTestCase {
+
+    @BeforeClass
+    public static void setupClass() {
+        System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
+        System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty");
+    }
+
+    @Test
+    public void testClientClose() {
+        ZooKeeperThread sendThread = null;
+        ZooKeeperThread eventThread = null;
+        try {
+            ZooKeeper zooKeeper = new ZooKeeper("dummydomain.local:4096", 5000, DummyWatcher.INSTANCE);
+
+            Field cnxnField = zooKeeper.getClass().getDeclaredField("cnxn");
+            cnxnField.setAccessible(true);
+            ClientCnxn clientCnxn = (ClientCnxn) cnxnField.get(zooKeeper);
+            Field sendThreadField = ClientCnxn.class.getDeclaredField("sendThread");
+            sendThreadField.setAccessible(true);
+            sendThread = (ZooKeeperThread) sendThreadField.get(clientCnxn);
+            Field eventThreadField = ClientCnxn.class.getDeclaredField("eventThread");
+            eventThreadField.setAccessible(true);
+            eventThread = (ZooKeeperThread) eventThreadField.get(clientCnxn);
+
+            zooKeeper.close();
+            Thread.sleep(1000);

Review Comment:
   My  Pull request title looks different from others. Do I need to clost it and open it again?



-- 
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: notifications-unsubscribe@zookeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [zookeeper] kezhuw commented on a diff in pull request #1864: fix: Thread leaks occur when dns fails.

Posted by GitBox <gi...@apache.org>.
kezhuw commented on code in PR #1864:
URL: https://github.com/apache/zookeeper/pull/1864#discussion_r858450514


##########
zookeeper-server/src/test/java/org/apache/zookeeper/ClientCloseTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper;
+
+import org.apache.zookeeper.client.ZKClientConfig;
+import org.apache.zookeeper.server.ServerCnxnFactory;
+import org.apache.zookeeper.server.ZooKeeperThread;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+
+public class ClientCloseTest extends ZKTestCase {
+
+    @BeforeClass
+    public static void setupClass() {
+        System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
+        System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty");
+    }
+
+    @Test
+    public void testClientClose() {
+        ZooKeeperThread sendThread = null;
+        ZooKeeperThread eventThread = null;
+        try {
+            ZooKeeper zooKeeper = new ZooKeeper("dummydomain.local:4096", 5000, DummyWatcher.INSTANCE);
+
+            Field cnxnField = zooKeeper.getClass().getDeclaredField("cnxn");
+            cnxnField.setAccessible(true);
+            ClientCnxn clientCnxn = (ClientCnxn) cnxnField.get(zooKeeper);
+            Field sendThreadField = ClientCnxn.class.getDeclaredField("sendThread");
+            sendThreadField.setAccessible(true);
+            sendThread = (ZooKeeperThread) sendThreadField.get(clientCnxn);
+            Field eventThreadField = ClientCnxn.class.getDeclaredField("eventThread");
+            eventThreadField.setAccessible(true);
+            eventThread = (ZooKeeperThread) eventThreadField.get(clientCnxn);
+
+            zooKeeper.close();
+            Thread.sleep(1000);

Review Comment:
   I think it would be sufficient if you could rename pr title, amend/squash commit, force-push branch. Open another pr sounds overkill in my opinion.



-- 
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: notifications-unsubscribe@zookeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [zookeeper] polaris-alioth commented on a diff in pull request #1864: fix: Thread leaks occur when dns fails.

Posted by GitBox <gi...@apache.org>.
polaris-alioth commented on code in PR #1864:
URL: https://github.com/apache/zookeeper/pull/1864#discussion_r857093305


##########
zookeeper-server/src/test/java/org/apache/zookeeper/ClientCloseTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper;
+
+import org.apache.zookeeper.client.ZKClientConfig;
+import org.apache.zookeeper.server.ServerCnxnFactory;
+import org.apache.zookeeper.server.ZooKeeperThread;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+
+public class ClientCloseTest extends ZKTestCase {
+
+    @BeforeClass
+    public static void setupClass() {
+        System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
+        System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty");
+    }
+
+    @Test
+    public void testClientClose() {
+        ZooKeeperThread sendThread = null;
+        ZooKeeperThread eventThread = null;
+        try {

Review Comment:
   That's really a good idea.



-- 
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: notifications-unsubscribe@zookeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [zookeeper] polaris-alioth commented on a diff in pull request #1864: fix: Thread leaks occur when dns fails.

Posted by GitBox <gi...@apache.org>.
polaris-alioth commented on code in PR #1864:
URL: https://github.com/apache/zookeeper/pull/1864#discussion_r857078115


##########
zookeeper-server/src/test/java/org/apache/zookeeper/ClientCloseTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper;
+
+import org.apache.zookeeper.client.ZKClientConfig;
+import org.apache.zookeeper.server.ServerCnxnFactory;
+import org.apache.zookeeper.server.ZooKeeperThread;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+
+public class ClientCloseTest extends ZKTestCase {
+
+    @BeforeClass
+    public static void setupClass() {
+        System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
+        System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty");
+    }
+
+    @Test
+    public void testClientClose() {
+        ZooKeeperThread sendThread = null;
+        ZooKeeperThread eventThread = null;
+        try {

Review Comment:
   I agree with you. It's a good way for the UT.



-- 
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: notifications-unsubscribe@zookeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [zookeeper] kezhuw commented on a diff in pull request #1864: fix: Thread leaks occur when dns fails.

Posted by GitBox <gi...@apache.org>.
kezhuw commented on code in PR #1864:
URL: https://github.com/apache/zookeeper/pull/1864#discussion_r856003034


##########
zookeeper-server/src/test/java/org/apache/zookeeper/ClientCloseTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper;
+
+import org.apache.zookeeper.client.ZKClientConfig;
+import org.apache.zookeeper.server.ServerCnxnFactory;
+import org.apache.zookeeper.server.ZooKeeperThread;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+
+public class ClientCloseTest extends ZKTestCase {
+
+    @BeforeClass
+    public static void setupClass() {
+        System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
+        System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty");
+    }
+
+    @Test
+    public void testClientClose() {
+        ZooKeeperThread sendThread = null;
+        ZooKeeperThread eventThread = null;
+        try {

Review Comment:
   Should we drop this `try` ? The test case will fail with full stacktrace in case of no fix and this `try`. I think it is more obvious to fail this way instead of thread state assertions. 



##########
zookeeper-server/src/test/java/org/apache/zookeeper/ClientCloseTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper;
+
+import org.apache.zookeeper.client.ZKClientConfig;
+import org.apache.zookeeper.server.ServerCnxnFactory;
+import org.apache.zookeeper.server.ZooKeeperThread;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+
+public class ClientCloseTest extends ZKTestCase {
+
+    @BeforeClass
+    public static void setupClass() {
+        System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
+        System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty");
+    }
+
+    @Test
+    public void testClientClose() {
+        ZooKeeperThread sendThread = null;
+        ZooKeeperThread eventThread = null;
+        try {
+            ZooKeeper zooKeeper = new ZooKeeper("dummydomain.local:4096", 5000, DummyWatcher.INSTANCE);
+
+            Field cnxnField = zooKeeper.getClass().getDeclaredField("cnxn");
+            cnxnField.setAccessible(true);
+            ClientCnxn clientCnxn = (ClientCnxn) cnxnField.get(zooKeeper);
+            Field sendThreadField = ClientCnxn.class.getDeclaredField("sendThread");
+            sendThreadField.setAccessible(true);
+            sendThread = (ZooKeeperThread) sendThreadField.get(clientCnxn);
+            Field eventThreadField = ClientCnxn.class.getDeclaredField("eventThread");
+            eventThreadField.setAccessible(true);
+            eventThread = (ZooKeeperThread) eventThreadField.get(clientCnxn);
+
+            zooKeeper.close();
+            Thread.sleep(1000);

Review Comment:
   Maybe we should join `eventThread` also in `ClientCnxn.disconnect` ? This way `ZooKeeper.close` gain strong semantics that either it fails or success with all attendant threads terminated. What do you think @eolivelli @maoling @symat  ?



-- 
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: notifications-unsubscribe@zookeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org