openvidu-server: protect concurrent recording start methods

pull/508/head
pabloFuente 2020-06-12 13:21:56 +02:00
parent d5b3b9dde7
commit a3406d3dfe
2 changed files with 51 additions and 30 deletions

View File

@ -80,7 +80,7 @@ public class Session implements SessionInterface {
/**
* This lock protects initialization of ALWAYS recordings upon first user
* publishing
* publishing, as well as POST /api/recordings/start
*/
public Lock recordingLock = new ReentrantLock();

View File

@ -230,6 +230,13 @@ public class RecordingManager {
}
public Recording startRecording(Session session, RecordingProperties properties) throws OpenViduException {
try {
if (session.recordingLock.tryLock(15, TimeUnit.SECONDS)) {
try {
if (sessionIsBeingRecorded(session.getSessionId())) {
throw new OpenViduException(Code.RECORDING_START_ERROR_CODE,
"Concurrent start of recording for session " + session.getSessionId());
} else {
Recording recording = null;
try {
switch (properties.outputMode()) {
@ -263,6 +270,20 @@ public class RecordingManager {
}
return recording;
}
} finally {
session.recordingLock.unlock();
}
} else {
throw new OpenViduException(Code.RECORDING_START_ERROR_CODE,
"Timeout waiting for recording Session lock to be available for session "
+ session.getSessionId());
}
} catch (InterruptedException e) {
throw new OpenViduException(Code.RECORDING_START_ERROR_CODE,
"InterruptedException waiting for recording Session lock to be available for session "
+ session.getSessionId());
}
}
public Recording stopRecording(Session session, String recordingId, EndReason reason) {
Recording recording;