Skip to content

Commit

Permalink
openvidu-server: selectAndRemoveKmsLock tryLock fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloFuente committed Apr 1, 2020
1 parent e647b28 commit aecb009
Showing 1 changed file with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class KurentoSessionManager extends SessionManager {
/* Protected by Session.closingLock.readLock */
public synchronized void joinRoom(Participant participant, String sessionId, Integer transactionId) {
Set<Participant> existingParticipants = null;
boolean lockAcquired = false;
try {

KurentoSession kSession = (KurentoSession) sessions.get(sessionId);
Expand All @@ -107,24 +108,21 @@ public synchronized void joinRoom(Participant participant, String sessionId, Int

try {
if (KmsManager.selectAndRemoveKmsLock.tryLock(MS_MAX_LOCK_WAIT, TimeUnit.SECONDS)) {
lockAcquired = true;
Kms lessLoadedKms = null;
try {
Kms lessLoadedKms = null;
try {
lessLoadedKms = this.kmsManager.getLessLoadedAndRunningKms();
} catch (NoSuchElementException e) {
// Restore session not active
this.cleanCollections(sessionId);
this.storeSessionNotActive(sessionNotActive);
throw new OpenViduException(Code.ROOM_CANNOT_BE_CREATED_ERROR_CODE,
"There is no available Media Node where to initialize session '" + sessionId
+ "'");
}
log.info("KMS less loaded is {} with a load of {}", lessLoadedKms.getUri(),
lessLoadedKms.getLoad());
kSession = createSession(sessionNotActive, lessLoadedKms);
} finally {
KmsManager.selectAndRemoveKmsLock.unlock();
lessLoadedKms = this.kmsManager.getLessLoadedAndRunningKms();
} catch (NoSuchElementException e) {
// Restore session not active
this.cleanCollections(sessionId);
this.storeSessionNotActive(sessionNotActive);
throw new OpenViduException(Code.ROOM_CANNOT_BE_CREATED_ERROR_CODE,
"There is no available Media Node where to initialize session '" + sessionId + "'");
}
log.info("KMS less loaded is {} with a load of {}", lessLoadedKms.getUri(),
lessLoadedKms.getLoad());
kSession = createSession(sessionNotActive, lessLoadedKms);

} else {
String error = "Timeout of " + MS_MAX_LOCK_WAIT + " seconds waiting to acquire lock";
log.error(error);
Expand Down Expand Up @@ -153,6 +151,10 @@ public synchronized void joinRoom(Participant participant, String sessionId, Int
log.warn("PARTICIPANT {}: Error joining/creating session {}", participant.getParticipantPublicId(),
sessionId, e);
sessionEventsHandler.onParticipantJoined(participant, sessionId, null, transactionId, e);
} finally {
if (lockAcquired) {
KmsManager.selectAndRemoveKmsLock.unlock();
}
}
if (existingParticipants != null) {
sessionEventsHandler.onParticipantJoined(participant, sessionId, existingParticipants, transactionId, null);
Expand Down

0 comments on commit aecb009

Please sign in to comment.