Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Crash] JNI Code for Speechsynthesizer Finalizer (SafeHandle.releaseSynthesizerHandle) causes JVM Crash with EXCEPTION_ACCESS_VIOLATION #2701

Open
lmikulla opened this issue Dec 16, 2024 · 2 comments
Labels
update needed For items that are in progress but have not been updated

Comments

@lmikulla
Copy link

lmikulla commented Dec 16, 2024

crash-speechsdk.log
hs_err_pid15672.log

Occasionally the Finalizer Queue for Azure SpeechSynthesizer causes a full JVM Crash. Attached both the speechsdk log for a minimal reproducible example and the java crash dump.

Relevant detail from the crashdmp:

`
Current thread (0x000002afd5440000): JavaThread "Finalizer" daemon [_thread_in_vm, id=13272, stack(0x000000d3fd700000,0x000000d3fd800000)]

Stack: [0x000000d3fd700000,0x000000d3fd800000],  sp=0x000000d3fd7fee30,  free space=1019k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [jvm.dll+0x3b7f70]
C  [Microsoft.CognitiveServices.Speech.java.bindings.dll+0x7e9b]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J 1103  com.microsoft.cognitiveservices.speech.util.SafeHandle.releaseSynthesizerHandle(J)J (0 bytes) @ 0x000002afc1b3c28b [0x000002afc1b3c240+0x000000000000004b]
J 1077 c2 com.microsoft.cognitiveservices.speech.util.SafeHandle.close()V (1109 bytes) @ 0x000002afc1b38bfc [0x000002afc1b389a0+0x000000000000025c]
J 1209 c2 java.lang.ref.Finalizer.runFinalizer(Ljdk/internal/misc/JavaLangAccess;)V [email protected] (117 bytes) @ 0x000002afc1b5cae4 [0x000002afc1b5c7e0+0x0000000000000304]
j  java.lang.ref.Finalizer$FinalizerThread.run()V+46 [email protected]
v  ~StubRoutines::call_stub

siginfo: EXCEPTION_ACCESS_VIOLATION (0xc0000005), reading address 0x0000000000000008

`

Minimal example that reproduces the crash:

`java

private static class synth implements AutoCloseable
{
    private SpeechConfig           speechConfig;
    private AzureStreamToJMFStream outputStream;
    private AudioConfig            outputAudioConfig;
    private SpeechSynthesizer      synth;
    private int                    id;
    
    synth(int id) throws UnsupportedInputFormatException
    {
        this.id = id;
        System.out.println("new synth " + id);
        this.speechConfig = SpeechConfig.fromSubscription(AZURESPEECHKEY, AZURESPEECHREGION);
        speechConfig.setSpeechSynthesisVoiceName("en-US-AvaMultilingualNeural");
        speechConfig.setProperty(PropertyId.Speech_LogFilename, "D:\\speechsdk.log");
        var synthOutput = SpeechSynthesisOutputFormat.Raw8Khz8BitMonoALaw;
        speechConfig.setSpeechSynthesisOutputFormat(synthOutput);
        
        this.outputStream = new AzureStreamToJMFStream(EAudioFormat.ALAW, synthOutput);
        
        this.outputAudioConfig = AudioConfig.fromStreamOutput(this.outputStream.getStream());
        
        this.synth = new SpeechSynthesizer(speechConfig, outputAudioConfig);
    }
    
    public Future<SpeechSynthesisResult> speak(String text)
    {
        return this.synth.SpeakTextAsync(text);
    }
    
    @Override
    public void close()
    {
        System.out.println("closing synth " + id);
        this.synth.close();
        this.outputStream.close();
        this.outputAudioConfig.close();
        this.speechConfig.close();
    }
}

public static void main(String[] args) throws Exception
{
    int id = 0;
    while (true)
    {
        try (var synth = new synth(id++))
        {
            synth.speak("Hello");
            Thread.sleep(250l);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    
}

`

Effectively repeatedly opening and closing SpeechSynthesizer instances. AzureStreamToJMFStream here is a PushAudioOutputStreamCallback using PushAudioOutputStream.create(this) to create a PushAudioOutputStream.

When running the example i was able to reproduce the crash in 2 distinct runs after 2700 and after 5300 instances were created and closed, seemingly at random.

We first discovered the bug when it crashed our production java server. Crash occured with both version 1.35.0 and 1.40.0 of the client-sdk

Version of Speech SDK
1.40.0

Platform, Operating System, and Programming Language

OS: Windows Server 2022 und Windows 11 Pro
Programming language: Java OpenJDK 11
@lmikulla
Copy link
Author

Was able to reproduce the crash with the most current version 1.41.1 as well.

Copy link

github-actions bot commented Jan 6, 2025

This item has been open without activity for 19 days. Provide a comment on status and remove "update needed" label.

@github-actions github-actions bot added the update needed For items that are in progress but have not been updated label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
update needed For items that are in progress but have not been updated
Projects
None yet
Development

No branches or pull requests

1 participant