Skip to content

Commit

Permalink
Closing all connections when heartbeat timeout
Browse files Browse the repository at this point in the history
This was actually addressed in following pr.
Members and clients disconnect the connection as soon as
heartbeat timeout is detected.

hazelcast#12765

This pr fixes member side heartbeat monitor. It was not closing
the connections if the connection is not an owner connection.

fixes hazelcast#14094
  • Loading branch information
sancar committed Nov 12, 2018
1 parent 4036a97 commit 3934720
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
Expand Up @@ -79,7 +79,7 @@ public void cleanup() {
}

@Test
public void testConnectionClosed_whenHeartbeatStopped() throws InterruptedException {
public void testOwnerConnectionClosed_whenHeartbeatStopped() throws InterruptedException {
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());

Expand All @@ -102,6 +102,39 @@ public void connectionRemoved(Connection connection) {
assertOpenEventually(countDownLatch);
}

@Test
public void testNonOwnerConnectionClosed_whenHeartbeatStopped() throws InterruptedException {
hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();

HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
final ClientConnectionManager connectionManager = clientImpl.getConnectionManager();

assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(2, connectionManager.getActiveConnections().size());
}
});

final CountDownLatch countDownLatch = new CountDownLatch(1);
connectionManager.addConnectionListener(new ConnectionListener() {
@Override
public void connectionAdded(Connection connection) {

}

@Override
public void connectionRemoved(Connection connection) {
countDownLatch.countDown();
}
});

blockMessagesFromInstance(instance, client);
assertOpenEventually(countDownLatch);
}

@Test
public void testInvocation_whenHeartbeatStopped() throws InterruptedException {
hazelcastFactory.newHazelcastInstance();
Expand Down
Expand Up @@ -92,9 +92,9 @@ private void cleanupEndpointsWithDeadConnections() {
}

private void monitor(ClientEndpoint clientEndpoint) {
// C++ client sends heartbeat over its non-owner connections
// For other client types, disregard non-owner connections for heartbeat monitoring purposes
if (clientEndpoint.isOwnerConnection() == ClientType.CPP.equals(clientEndpoint.getClientType())) {
// C++ client does not send heartbeat over its owner connection
// We are skipping checking heartbeat for cpp owner connection
if (clientEndpoint.isOwnerConnection() && ClientType.CPP.equals(clientEndpoint.getClientType())) {
return;
}

Expand Down

0 comments on commit 3934720

Please sign in to comment.