GUAC-1101: Do not release connections more than once.

This commit is contained in:
Michael Jumper
2015-03-01 21:52:14 -08:00
parent 3f22026c9e
commit feaa2fd63a

View File

@@ -29,6 +29,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
import org.glyptodon.guacamole.auth.jdbc.connection.ModeledConnection;
import org.glyptodon.guacamole.auth.jdbc.connectiongroup.ModeledConnectionGroup;
@@ -173,6 +174,7 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
final ActiveConnectionRecord activeConnection = new ActiveConnectionRecord(user);
// Get relevant identifiers
final AtomicBoolean released = new AtomicBoolean(false);
final String identifier = connection.getIdentifier();
final String parentIdentifier = connection.getParentIdentifier();
@@ -217,7 +219,10 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
// Attempt to close connection
super.close();
// Release connection upon close
// Release connection upon close, if not already released
if (released.compareAndSet(false, true)) {
// Release connection
activeConnections.remove(identifier, activeConnection);
activeConnectionGroups.remove(parentIdentifier, activeConnection);
release(user, connection);
@@ -237,6 +242,8 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
}
} // end close()
};
}
@@ -244,10 +251,12 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
// Release connection in case of error
catch (GuacamoleException e) {
// Atomically release access to connection
// Release connection if not already released
if (released.compareAndSet(false, true)) {
activeConnections.remove(identifier, activeConnection);
activeConnectionGroups.remove(parentIdentifier, activeConnection);
release(user, connection);
}
throw e;