cognitive-services-speech-sdk: [MAS] Occasional JVM crashes during SpeechRecognizer dispose when using MAS
Hi there!
This is somehow related to #2124 but in contrast to other issues this one reproduced when using continuous recognition mode during clean up:
package com.speech.demo;
import com.microsoft.cognitiveservices.speech.audio.*;
import com.microsoft.cognitiveservices.speech.*;
public class Main {
private static boolean pass = false;
private static SpeechConfig initSpeechConfig(String speechSubscriptionKey, String serviceRegion) {
SpeechConfig speechConfig = SpeechConfig.fromSubscription(speechSubscriptionKey, serviceRegion);
speechConfig.setProperty(PropertyId.Speech_LogFilename, "/tmp/speech.log");
return speechConfig;
}
public static void feed(PushAudioInputStream input) {
byte[] buf = new byte[640];
while (true) {
try {
Thread.sleep(20);
if (pass) {
input.write(buf);
}
} catch (Exception ex) {
}
}
}
public static void main(String[] args) {
String speechSubscriptionKey = System.getenv("SPEECH_KEY");
String serviceRegion = System.getenv("SPEECH_REGION");
boolean useMas = Boolean.parseBoolean(System.getenv("SPEECH_USE_MAS"));
AudioStreamFormat format = AudioStreamFormat.getWaveFormat(16000, (short)16, (short)1, AudioStreamWaveFormat.PCM);
try (
final PushAudioInputStream input = PushAudioInputStream.create(format);
final AudioProcessingOptions audioOpts = useMas ? AudioProcessingOptions.create(
AudioProcessingConstants.AUDIO_INPUT_PROCESSING_ENABLE_DEFAULT,
PresetMicrophoneArrayGeometry.Mono,
SpeakerReferenceChannel.None) : null;
final AudioConfig audioConfig = useMas ? AudioConfig.fromStreamInput(input, audioOpts) :
AudioConfig.fromStreamInput(input);
final SpeechConfig speechConfig = initSpeechConfig(speechSubscriptionKey, serviceRegion);
final SpeechRecognizer reco = new SpeechRecognizer(speechConfig, audioConfig);
) {
System.out.printf("MAS: %s %s\n", useMas, audioOpts);
reco.recognized.addEventListener((s, e) -> {
SpeechRecognitionResult result = e.getResult();
if (result.getReason() == ResultReason.RecognizedSpeech) {
System.out.println("RECOGNIZED: " + result.getText());
}
else if (result.getReason() == ResultReason.NoMatch) {
NoMatchDetails noMatch = NoMatchDetails.fromResult(result);
System.out.println("NOMATCH: Reason=" + noMatch.getReason());
}
});
reco.canceled.addEventListener((s, e) -> {
System.out.println("CANCELED: Reason=" + e.getReason());
if (e.getReason() == CancellationReason.Error) {
System.out.println("CANCELED: ErrorCode=" + e.getErrorCode());
System.out.println("CANCELED: ErrorDetails=" + e.getErrorDetails());
}
});
reco.sessionStarted.addEventListener((s, e) -> {
System.out.println("Session started");
pass = true;
});
reco.sessionStopped.addEventListener((s, e) -> {
pass = false;
System.out.println("Session stopped");
});
Thread feedThread = new Thread(() -> feed(input));
feedThread.setDaemon(true);
feedThread.start();
Thread.sleep(2500);
reco.startContinuousRecognitionAsync().get();
Thread.sleep(2500);
reco.stopContinuousRecognitionAsync().get();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
format.close();
}
}
I’m running this code in a Docker container with Ubuntu Linux 20.04 and OpenJDK 11. It’s supposed it doesn’t matter if specific input audio stream to be used. Sample code generates zeroed by stream. The issue is not 100% reproducible but when it is it crashes all the JVM environment, not the app on it’s own. So in order to reproduce the crash I run the program in a loop like:
while :; do docker run -e SPEECH_USE_MAS=... ... || break; done
Expected behavior
When not using MAS everything works fine:
MAS: false null
Session started
NOMATCH: Reason=InitialSilenceTimeout
Session stopped
MAS: false null
Session started
NOMATCH: Reason=InitialSilenceTimeout
Session stopped
MAS: false null
Session started
NOMATCH: Reason=InitialSilenceTimeout
Session stopped
MAS: false null
Session started
NOMATCH: Reason=InitialSilenceTimeout
Session stopped
...
Log: speech.success.log
Actual behavior
But when MAS is involved (SPEECH_USE_MAS=true) once in a while the program causes JVM to crash:
MAS: true com.microsoft.cognitiveservices.speech.audio.AudioProcessingOptions@357246de
Session started
NOMATCH: Reason=InitialSilenceTimeout
Session stopped
MAS: true com.microsoft.cognitiveservices.speech.audio.AudioProcessingOptions@357246de
Session started
NOMATCH: Reason=InitialSilenceTimeout
Session stopped
MAS: true com.microsoft.cognitiveservices.speech.audio.AudioProcessingOptions@357246de
Session started
NOMATCH: Reason=InitialSilenceTimeout
Session stopped
MAS: true com.microsoft.cognitiveservices.speech.audio.AudioProcessingOptions@357246de
Session started
NOMATCH: Reason=InitialSilenceTimeout
Session stopped
terminate called without an active exception
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fa90ed53941, pid=1, tid=7
#
# JRE version: OpenJDK Runtime Environment (11.0.20.1+1) (build 11.0.20.1+1-post-Ubuntu-0ubuntu120.04)
# Java VM: OpenJDK 64-Bit Server VM (11.0.20.1+1-post-Ubuntu-0ubuntu120.04, mixed mode, sharing, tiered, compressed oops, serial gc, linux-amd64)
# Problematic frame:
# C [libc.so.6+0x22941] abort+0x213
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E" (or dumping to /app/core.1)
#
# An error report file with more information is saved as:
# /tmp/hs_err_pid1.log
#
# If you would like to submit a bug report, please visit:
# https://bugs.launchpad.net/ubuntu/+source/openjdk-lts
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Log: speech.failure.log
Additional details
The setup of MAS is pretty dummy in the sample merely to reproduce the issue. I’ve got same results if using SpeakerReferenceChannel.LastChannel. It seems that whether crash is reproduced or not is a subject to fine tuning sleep delays.
Version of the Cognitive Services Speech SDK
1.31.0
Platform, Operating System, and Programming Language
- OS: Ubuntu Linux 20.04 (docker)
- Hardware - x64
- Programming language: Java OpenJDK 11
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (3 by maintainers)
Thanks! I was able to reproduce the issue and figure out the root cause. I will fix it soon.