Skip to content

Commit a4cb589

Browse files
committed
Patch for race condition for Calls that execute Record verb and receive a Bye from client.
This close #2313
1 parent abcc72b commit a4cb589

File tree

7 files changed

+397
-62
lines changed

7 files changed

+397
-62
lines changed

Diff for: restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/BaseVoiceInterpreter.java

+63-58
Original file line numberDiff line numberDiff line change
@@ -1800,67 +1800,72 @@ public void execute(final Object message) throws Exception {
18001800
final Recording recording = builder.build();
18011801
final RecordingsDao recordings = storage.getRecordingsDao();
18021802
recordings.addRecording(recording);
1803-
// Start transcription.
1804-
URI transcribeCallback = null;
1805-
Attribute attribute = verb.attribute("transcribeCallback");
1806-
if (attribute != null) {
1807-
final String value = attribute.value();
1808-
if (value != null && !value.isEmpty()) {
1809-
try {
1810-
transcribeCallback = URI.create(value);
1811-
} catch (final Exception exception) {
1812-
final Notification notification = notification(ERROR_NOTIFICATION, 11100, transcribeCallback
1813-
+ " is an invalid URI.");
1814-
notifications.addNotification(notification);
1815-
sendMail(notification);
1816-
final StopInterpreter stop = new StopInterpreter();
1817-
source.tell(stop, source);
1818-
return;
1819-
}
1820-
}
1821-
}
1822-
boolean transcribe = false;
1823-
if (transcribeCallback != null) {
1824-
transcribe = true;
1825-
} else {
1826-
attribute = verb.attribute("transcribe");
1803+
1804+
Attribute attribute = null;
1805+
1806+
if (checkAsrService()) {
1807+
// ASR service is enabled. Start transcription.
1808+
URI transcribeCallback = null;
1809+
attribute = verb.attribute("transcribeCallback");
18271810
if (attribute != null) {
18281811
final String value = attribute.value();
18291812
if (value != null && !value.isEmpty()) {
1830-
transcribe = Boolean.parseBoolean(value);
1813+
try {
1814+
transcribeCallback = URI.create(value);
1815+
} catch (final Exception exception) {
1816+
final Notification notification = notification(ERROR_NOTIFICATION, 11100, transcribeCallback
1817+
+ " is an invalid URI.");
1818+
notifications.addNotification(notification);
1819+
sendMail(notification);
1820+
final StopInterpreter stop = new StopInterpreter();
1821+
source.tell(stop, source);
1822+
return;
1823+
}
18311824
}
18321825
}
1833-
}
1834-
if (transcribe && checkAsrService()) {
1835-
final Sid sid = Sid.generate(Sid.Type.TRANSCRIPTION);
1836-
final Transcription.Builder otherBuilder = Transcription.builder();
1837-
otherBuilder.setSid(sid);
1838-
otherBuilder.setAccountSid(accountId);
1839-
otherBuilder.setStatus(Transcription.Status.IN_PROGRESS);
1840-
otherBuilder.setRecordingSid(recordingSid);
1841-
otherBuilder.setTranscriptionText("Transcription Text not available");
1842-
otherBuilder.setDuration(duration);
1843-
otherBuilder.setPrice(new BigDecimal("0.00"));
1844-
buffer = new StringBuilder();
1845-
buffer.append("/").append(version).append("/Accounts/").append(accountId.toString());
1846-
buffer.append("/Transcriptions/").append(sid.toString());
1847-
final URI uri = URI.create(buffer.toString());
1848-
otherBuilder.setUri(uri);
1849-
final Transcription transcription = otherBuilder.build();
1850-
final TranscriptionsDao transcriptions = storage.getTranscriptionsDao();
1851-
transcriptions.addTranscription(transcription);
1852-
try {
1853-
final Map<String, Object> attributes = new HashMap<String, Object>();
1854-
attributes.put("callback", transcribeCallback);
1855-
attributes.put("transcription", transcription);
1856-
getAsrService().tell(new AsrRequest(new File(recordingUri), "en", attributes), source);
1857-
outstandingAsrRequests++;
1858-
} catch (final Exception exception) {
1859-
logger.error(exception.getMessage(), exception);
1826+
boolean transcribe = false;
1827+
if (transcribeCallback != null) {
1828+
transcribe = true;
1829+
} else {
1830+
attribute = verb.attribute("transcribe");
1831+
if (attribute != null) {
1832+
final String value = attribute.value();
1833+
if (value != null && !value.isEmpty()) {
1834+
transcribe = Boolean.parseBoolean(value);
1835+
}
1836+
}
1837+
}
1838+
if (transcribe && checkAsrService()) {
1839+
final Sid sid = Sid.generate(Sid.Type.TRANSCRIPTION);
1840+
final Transcription.Builder otherBuilder = Transcription.builder();
1841+
otherBuilder.setSid(sid);
1842+
otherBuilder.setAccountSid(accountId);
1843+
otherBuilder.setStatus(Transcription.Status.IN_PROGRESS);
1844+
otherBuilder.setRecordingSid(recordingSid);
1845+
otherBuilder.setTranscriptionText("Transcription Text not available");
1846+
otherBuilder.setDuration(duration);
1847+
otherBuilder.setPrice(new BigDecimal("0.00"));
1848+
buffer = new StringBuilder();
1849+
buffer.append("/").append(version).append("/Accounts/").append(accountId.toString());
1850+
buffer.append("/Transcriptions/").append(sid.toString());
1851+
final URI uri = URI.create(buffer.toString());
1852+
otherBuilder.setUri(uri);
1853+
final Transcription transcription = otherBuilder.build();
1854+
final TranscriptionsDao transcriptions = storage.getTranscriptionsDao();
1855+
transcriptions.addTranscription(transcription);
1856+
try {
1857+
final Map<String, Object> attributes = new HashMap<String, Object>();
1858+
attributes.put("callback", transcribeCallback);
1859+
attributes.put("transcription", transcription);
1860+
getAsrService().tell(new AsrRequest(new File(recordingUri), "en", attributes), source);
1861+
outstandingAsrRequests++;
1862+
} catch (final Exception exception) {
1863+
logger.error(exception.getMessage(), exception);
1864+
}
18601865
}
18611866
} else if(logger.isInfoEnabled()){
1862-
logger.info("AsrService activated but not properly configured. Please set api-key for AsrService");
1863-
}
1867+
logger.info("AsrService is not enabled");
1868+
}
18641869

18651870
// If action is present redirect to the action URI.
18661871
String action = null;
@@ -1946,11 +1951,11 @@ public void execute(final Object message) throws Exception {
19461951
if (CallStateChanged.class.equals(klass) ) {
19471952
if (action == null || action.isEmpty()) {
19481953
source.tell(new StopInterpreter(), source);
1954+
} else {
1955+
// Ask the parser for the next action to take.
1956+
final GetNextVerb next = new GetNextVerb();
1957+
parser.tell(next, source);
19491958
}
1950-
} else {
1951-
// Ask the parser for the next action to take.
1952-
final GetNextVerb next = new GetNextVerb();
1953-
parser.tell(next, source);
19541959
}
19551960
// A little clean up.
19561961
recordingSid = null;

Diff for: restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/VoiceInterpreter.java

+12
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,10 @@ private void onParserFailed(Object message) throws TransitionFailedException, Tr
717717

718718
private void onStopInterpreter(Object message) throws TransitionFailedException, TransitionNotFoundException, TransitionRollbackException {
719719
this.liveCallModification = ((StopInterpreter) message).isLiveCallModification();
720+
if (logger.isInfoEnabled()) {
721+
String msg = String.format("Got StopInterpreter, liveCallModification %s, CallState %s", liveCallModification, callState);
722+
logger.info(msg);
723+
}
720724
if (CallStateChanged.State.IN_PROGRESS.equals(callState) && !liveCallModification) {
721725
fsm.transition(message, hangingUp);
722726
} else {
@@ -818,10 +822,18 @@ else if (is(gathering) || (is(finishGathering) && !super.dtmfReceived)) {
818822
private void onEndMessage(Object message) throws TransitionFailedException, TransitionNotFoundException, TransitionRollbackException {
819823
//Because of RMS issue https://github.com/RestComm/mediaserver/issues/158 we cannot have List<URI> for waitUrl
820824
if (playWaitUrlPending && conferenceWaitUris != null && conferenceWaitUris.size() > 0) {
825+
if (logger.isInfoEnabled()) {
826+
String msg = String.format("End tag received, playWaitUrlPending is %s, conferenceWaitUris.size() %d",playWaitUrlPending, conferenceWaitUris.size());
827+
logger.info(msg);
828+
}
821829
fsm.transition(conferenceWaitUris, conferencing);
822830
return;
823831
}
824832
if (callState.equals(CallStateChanged.State.COMPLETED) || callState.equals(CallStateChanged.State.CANCELED)) {
833+
if(logger.isInfoEnabled()) {
834+
String msg = String.format("End tag received, Call state %s , VI state %s will move to finished state",callState, fsm.state());
835+
logger.info(msg);
836+
}
825837
fsm.transition(message, finished);
826838
} else {
827839
if (!isParserFailed) {

Diff for: restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,10 @@ protected void notificationResponse(final Object message, final ActorRef sender)
453453
final int transaction = rqnt.getTransactionHandle();
454454
response.setTransactionHandle(transaction);
455455
try {
456-
Thread.sleep(sleepTime);
456+
Thread.sleep(sleepTime*10);
457457
} catch (InterruptedException e) {
458458
}
459-
System.out.println(response.toString());
459+
logger.info("About to send MockMediaGateway response: "+response.toString());
460460
sender.tell(response, self);
461461
}
462462

Diff for: restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Call.java

+11
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,10 @@ private void onStopMediaGroup(StopMediaGroup message, ActorRef self, ActorRef se
18141814
liveCallModification = true;
18151815
self().tell(new Leave(true), self());
18161816
}
1817+
} else {
1818+
if (logger.isDebugEnabled()) {
1819+
logger.debug("Got StopMediaGroup but Call is already in state: "+fsm.state());
1820+
}
18171821
}
18181822
}
18191823

@@ -2195,6 +2199,13 @@ private void onHangup(Hangup message, ActorRef self, ActorRef sender) throws Exc
21952199
logger.debug("Got Hangup: "+message+" for Call, from: "+from+" to: "+to+" state: "+fsm.state()+" conferencing: "+conferencing +" conference: "+conference);
21962200
}
21972201

2202+
if (is(completed)) {
2203+
if (logger.isDebugEnabled()) {
2204+
logger.debug("Got Hangup but already in completed state");
2205+
}
2206+
return;
2207+
}
2208+
21982209
// Stop recording if necessary
21992210
if (recording) {
22002211
recording = false;

0 commit comments

Comments
 (0)