Github user hanm commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/156#discussion_r98120457
--- Diff: src/java/test/org/apache/zookeeper/server/NIOServerCnxnTest.java
---
@@ -68,4 +69,38 @@ public void testOperationsAfterCnxnClose() throws
IOException,
zk.close();
}
}
+
+ /**
+ * Mock extension of NIOServerCnxn to test for
+ * CancelledKeyException (ZOOKEEPER-2044).
+ */
+ private static class MockNIOServerCnxn extends NIOServerCnxn {
+ public MockNIOServerCnxn(NIOServerCnxn cnxn)
+ throws IOException {
+ super(cnxn.zkServer, cnxn.sock, cnxn.sk, cnxn.factory);
+ }
+
+ public void mockSendBuffer(ByteBuffer bb) throws Exception {
+ super.internalSendBuffer(bb);
+ }
+ }
+
+ @Test(timeout = 30000)
+ public void testValidSelectionKey() throws Exception {
+ final ZooKeeper zk = createClient();
+ try {
+ Iterable<ServerCnxn> connections =
serverFactory.getConnections();
+ for (ServerCnxn serverCnxn : connections) {
+ MockNIOServerCnxn mock = new
MockNIOServerCnxn((NIOServerCnxn) serverCnxn);
+ // Cancel key
+ ((NIOServerCnxn)
serverCnxn).sock.keyFor(((NIOServerCnxnFactory)
serverFactory).selector).cancel();;
+ mock.mockSendBuffer(ByteBuffer.allocate(8));
+ }
+ } catch (CancelledKeyException e) {
+ LOG.error("Exception while sending bytes!", e);
+ Assert.fail(e.toString());
+ } finally {
+ zk.close();
--- End diff --
@rakeshadr Good observation on the long running of the test. This is
definitely something we should fix. The actual delay indeed happens at client
close and the root cause is session timeout: when a client closing itself it
sends a request to server, and this request packet will stuck forever in our
case because server has canceled the selector; so client session will expire
eventually and by default, the timeout value between client / server is set as
30 sec and 2/3 about it - which is 20 sec is exactly what it would cost for a
heart beat to fail. I fixed this by adjusting the timeout value to 3 sec
instead just for this single test. PTAL.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---