Bug 60058 - Xamarin.iOS app hangs for a few seconds when Disposing of AudioToolbox.InputAudioQueue only after freeing buffers via InputAudioQueue.FreeBuffer().
Summary: Xamarin.iOS app hangs for a few seconds when Disposing of AudioToolbox.InputA...
Status: RESOLVED DUPLICATE of bug 59911
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 11.0 (xcode9)
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-10-09 16:02 UTC by Ammar Mheir
Modified: 2017-10-09 17:34 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample Project (14.42 KB, application/x-zip-compressed)
2017-10-09 16:02 UTC, Ammar Mheir
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED DUPLICATE of bug 59911

Description Ammar Mheir 2017-10-09 16:02:44 UTC
Created attachment 25226 [details]
Sample Project

## Overview

Utilizing InputAudioQueue from the AudioToolbox namespace in Xamarin.iOS for recording audio. When stopping the recording session, the application will hang for a few seconds (or sometimes indefinitly hang) when InputAudioQueue has been flagged for disposal after calling InputAudioQueue.FreeBuffer. 

If audio buffers are not freed and InputAudioQueue.Dispose is called, the app will function as expected and will not hang when the code tries to flag that object for disposal, however if .FreeBuffer() was called before the .Dispose, the app will hang on the .Dispose after Freeing Buffers. 

##Steps to reproduce

1). Download attached sample
2). After building and deploying to Simulator or Device, click on Start Recording
3). After a few seconds, click on Stop Recording
4). The UITextView will indicate the status of the application, notice how the app seems to have frozen up until it finally moves past the .Dispose call. (Line 109 in ViewController.cs)
5). Go into the ViewController.cs file and comment out the code that frees the audio buffers on lines 102-103.
6). Run the app again, Start Recording then Stop, notice how the InputAudioQueue gets Disposed of immediately this time when the buffers are not first freed. 

I've added Console logs as well just to indicate when the buffers are freed and when .Dispose has been called on InputAudioQueue to show the timing between calls. 

##Current Results

Xamarin.iOS application will hang when .Dispose is called on InputAudioQueue after calling InputAudioQueue.FreeBuffers but will not hang if we do not Free the audio Buffers first. 

##Expected Results

Xamarin.iOS application would Dispose of the InputAudioQueue without hanging the UI even after first freeing audio buffers via InputAudioQueue.FreeBuffer().

##Additional Information

Moving the FreeBuffers call into an async method does help however this can pose some issues as the .Dispose still does take a while to complete and users can start a new recording without waiting for the previous InputAudioQueue to complete disposal. My main question is if this is the expected outcome as calling .Dispose on other objects does not cause this hang.
Comment 1 Alex Soto [MSFT] 2017-10-09 17:34:18 UTC

*** This bug has been marked as a duplicate of bug 59911 ***