mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: protect concurrent recording start methods
parent
d5b3b9dde7
commit
a3406d3dfe
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue