[
https://issues.apache.org/jira/browse/CAMEL-24488?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Andrea Cosentino resolved CAMEL-24488.
--------------------------------------
Resolution: Fixed
> camel-ibm-watson-speech-to-text: WatsonSpeechToTextProducer leaks the audio
> FileInputStream
> -------------------------------------------------------------------------------------------
>
> Key: CAMEL-24488
> URL: https://issues.apache.org/jira/browse/CAMEL-24488
> Project: Camel
> Issue Type: Bug
> Reporter: Andrea Cosentino
> Assignee: Andrea Cosentino
> Priority: Major
> Fix For: 4.22.1, 4.23.0, 4.18.5
>
>
> WatsonSpeechToTextProducer.recognize() opens a FileInputStream for the audio
> input — either from the CamelIbmWatsonSttAudioFile header (a File) or from a
> File message body — but never closes it. There is no try/finally or
> try-with-resources around the stt.recognize(options).execute() call, so on
> every invocation that supplies a File (and on any exception thrown during
> recognition) the file descriptor is leaked.
> {code:java}
> if (audioFile != null) {
> audioStream = new FileInputStream(audioFile); // opened, never
> closed
> } else {
> audioStream = exchange.getIn().getBody(InputStream.class);
> if (audioStream == null) {
> File bodyFile = exchange.getIn().getBody(File.class);
> if (bodyFile != null) {
> audioStream = new FileInputStream(bodyFile); // opened, never
> closed
> }
> }
> }
> ...
> SpeechRecognitionResults results =
> stt.recognize(options).execute().getResult();
> {code}
> Only the producer-opened stream should be closed. When the audio is supplied
> as an exchange-body InputStream the caller owns it and it must NOT be closed
> by the producer. Fix: track an ownStream flag (set only for the two
> FileInputStream cases) and close the stream via IOHelper.close in a finally
> block around the recognition, only when the producer opened it.
> Affected: components/camel-ibm/camel-ibm-watson-speech-to-text
> (org.apache.camel.component.ibm.watson.stt.WatsonSpeechToTextProducer).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)