Unclosed resource in \Drupal\ai\Base\OpenAiBasedProviderClientBase::speechToText()
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3558536. --> Reported by: [mxr576](https://www.drupal.org/user/315522) Related to !1020 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>A resource is opened in <code>\Drupal\ai\Base\OpenAiBasedProviderClientBase::speechToText()</code>.</p> <pre> $path = $this-&gt;fileSystem-&gt;saveData($input, 'temporary://speech_to_text.mp3', FileExists::Replace);<br>&nbsp;&nbsp;&nbsp; $input = fopen($path, 'r');<br><br>&nbsp;&nbsp;&nbsp; $payload = [<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'model' =&gt; $model_id,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'file' =&gt; $input,<br>&nbsp;&nbsp;&nbsp; ] + $this-&gt;configuration;<br><br>&nbsp;&nbsp;&nbsp; try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $response = $this-&gt;client-&gt;audio()-&gt;transcribe($payload)-&gt;toArray();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new SpeechToTextOutput($response['text'], $response, []);<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; catch (\Exception $e) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;handleApiException($e);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw $e;<br>&nbsp;&nbsp;&nbsp; }</pre><h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4> <p>Please provide information like AI modules enabled, which AI provider, browser, etc.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Close the resource when the operation is done or an error occured.</p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3>
issue