Skip to content

Commit

Permalink
Dont keep the endpoint reference to clean client resources
Browse files Browse the repository at this point in the history
We are scheduling a task to clean client resources after some
time(60 seconds). Eventough endpoint is removed, we were keeping
a reference to it via this task. This was causing unncessary leak
for 60 seconds since the endpoint keeps reference to heavy objects
like `connection`.

With this pr, we are passing only necessary fields objects of
client endpoint to task to avoid keeping reference to the client
endpoint itself.
  • Loading branch information
sancar committed Sep 13, 2018
1 parent 4432bdd commit e3632c6
Showing 1 changed file with 6 additions and 5 deletions.
Expand Up @@ -456,13 +456,15 @@ public void connectionRemoved(Connection connection) {
}

String localMemberUuid = node.getThisUuid();
String ownerUuid = ownershipMappings.get(endpoint.getUuid());
final String clientUuid = endpoint.getUuid();
String ownerUuid = ownershipMappings.get(clientUuid);
if (localMemberUuid.equals(ownerUuid)) {
final long authenticationCorrelationId = endpoint.getAuthenticationCorrelationId();
try {
nodeEngine.getExecutionService().schedule(new Runnable() {
@Override
public void run() {
callDisconnectionOperation(endpoint);
callDisconnectionOperation(clientUuid, authenticationCorrelationId);
}
}, endpointRemoveDelaySeconds, TimeUnit.SECONDS);
} catch (RejectedExecutionException e) {
Expand All @@ -473,19 +475,18 @@ public void run() {
}
}

private void callDisconnectionOperation(ClientEndpointImpl endpoint) {
private void callDisconnectionOperation(String clientUuid, long authenticationCorrelationId) {
Collection<Member> memberList = nodeEngine.getClusterService().getMembers();
OperationService operationService = nodeEngine.getOperationService();
String memberUuid = getLocalMember().getUuid();
String clientUuid = endpoint.getUuid();

String ownerMember = ownershipMappings.get(clientUuid);
if (!memberUuid.equals(ownerMember)) {
// do nothing if the owner already changed (double checked locking)
return;
}

if (lastAuthenticationCorrelationIds.get(clientUuid).get() > endpoint.getAuthenticationCorrelationId()) {
if (lastAuthenticationCorrelationIds.get(clientUuid).get() > authenticationCorrelationId) {
//a new authentication already made for that client. This check is needed to detect
// "a disconnected client is reconnected back to same node"
return;
Expand Down

0 comments on commit e3632c6

Please sign in to comment.