# sound.readData blocking call on error when streaming

**URL:** <https://qa.fmod.com/t/sound-readdata-blocking-call-on-error-when-streaming/12582>\
**Category:** Unity\
**Created:** [July 11, 2016, 2:25pm UTC](https://qa.fmod.com/t/sound-readdata-blocking-call-on-error-when-streaming/12582 "2016-07-11T14:25:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![r618](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/r618/32/36_2.png) [@r618](https://qa.fmod.com/u/r618)\
**Post date:** [July 11, 2016, 2:25pm UTC](https://qa.fmod.com/t/sound-readdata-blocking-call-on-error-when-streaming/12582/1 "2016-07-11T14:25:43Z")

</div>

Hi,

I’m using the low level API C# wrapper in Unity to manually drive the streaming, such that:

just a call to `createSound`  
no `playSound` and no `getChannel` calls

manually retrieving decoded stream via  
`sound.readData`  
in a separate thread.

Works almost for all situations as intended, except

- `getOpenState` starving flag is unreliable (is not set) in this case - I’m using a workaround by monitoring the buffer percentage ( not, unfortunately 100% reliable, too ) but what is worse
- `sound.readData` blocks on stream error - i.e. when the network is lost, or file playback is finished.

On Windows, it seems like it is blocking on `WaitForSocket`call and never / until a timeout expires returns.

Is there a way to inspect the stream condition other than by calling ‘getOpenState’ and / or a way to for `sound.readData`to actually return proper error code when there’s no data available in this scenario ?

Thanks!

---

<div class="post-metadata">

**Author:** ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)\
**Post date:** [July 15, 2016, 4:46am UTC](https://qa.fmod.com/t/sound-readdata-blocking-call-on-error-when-streaming/12582/2 "2016-07-15T04:46:36Z")

</div>

Firstly the starving check only applies to **playing** streams.

Can you give more details about your stream? I can’t repro a hang when a connection to a shoutcast server is closed while blocking in readData.

---

<div class="post-metadata">

**Author:** ![r618](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/r618/32/36_2.png) [@r618](https://qa.fmod.com/u/r618)\
**Post date:** [July 15, 2016, 5:04am UTC](https://qa.fmod.com/t/sound-readdata-blocking-call-on-error-when-streaming/12582/3 "2016-07-15T05:04:10Z")

</div>

> [@](#):
>
> Firstly the starving check only applies to **playing** streams.
> 
> Can you give more details about your stream? I can’t repro a hang when a connection to a shoutcast server is closed while blocking in readData.

Hi Nicholas, thanks for reply !

I can live with starving flag being updated only for playing streams, no problem;

It could be reproduced on practically any stream I’ve tried while testing - for example on somafm: [http://ice1.somafm.com/thetrip-128-mp3](http://ice1.somafm.com/thetrip-128-mp3)

One note though: the readData is called on different thread than main thread.  
– i suppose that might be the problem.

( Unity has a special audio thread callback where current raw audio buffer can be accessed - I am using it to fill audio buffer with decoded stream data - it works without problems, except when the stream breaks… )

I wanted to test directly from e.g. netstream sample without c# wrapper, but I assumed that it would probably behave the same.

If you fail to reproduce it again, I will try to setup FMOD5 test case.

Thanks for looking into it once again!

---

<div class="post-metadata">

**Author:** ![r618](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/r618/32/36_2.png) [@r618](https://qa.fmod.com/u/r618)\
**Post date:** [July 17, 2016, 5:50am UTC](https://qa.fmod.com/t/sound-readdata-blocking-call-on-error-when-streaming/12582/4 "2016-07-17T05:50:11Z")

</div>

Hello,

I’ve managed to strip down everything to ~ 300 LOC and a single MonoBehaviour ( it’s basically adapted net\_stream from FMOD Studio API Windows lowlevel samples ).  
It’s reproducible every time the network disappears ( meaning physically unplugging the network cord / turning off WiFi, until the buffer is starved )  
Tested with Unity 5.1 and 5.3 in the editor and win64 standalone builds.

Is there any way to possibly send a repro case / some other approriate way ?  
Thanks!

---

<div class="post-metadata">

**Author:** ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)\
**Post date:** [July 18, 2016, 1:52am UTC](https://qa.fmod.com/t/sound-readdata-blocking-call-on-error-when-streaming/12582/5 "2016-07-18T01:52:18Z")

</div>

We don’t have anything for public uploads. You can host it yourself and send us the link to [support@fmod.org](mailto:support@fmod.org), or it’s small enough it can be sent as an attachment.

---

<div class="post-metadata">

**Author:** ![r618](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/r618/32/36_2.png) [@r618](https://qa.fmod.com/u/r618)\
**Post date:** [July 18, 2016, 9:04am UTC](https://qa.fmod.com/t/sound-readdata-blocking-call-on-error-when-streaming/12582/6 "2016-07-18T09:04:15Z")

</div>

Thanks, email sent.

---

<div class="post-metadata">

**Author:** ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)\
**Post date:** [July 22, 2016, 6:31am UTC](https://qa.fmod.com/t/sound-readdata-blocking-call-on-error-when-streaming/12582/7 "2016-07-22T06:31:59Z")

</div>

We’ve reproduced the issue. We’re trying to find the best solution across all our platforms.

Edit: This will be fixed in 1.08.09 which will be released early August.

---

<div class="post-metadata">

**Author:** ![r618](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/r618/32/36_2.png) [@r618](https://qa.fmod.com/u/r618)\
**Post date:** [July 22, 2016, 12:30pm UTC](https://qa.fmod.com/t/sound-readdata-blocking-call-on-error-when-streaming/12582/8 "2016-07-22T12:30:18Z")

</div>

> [@](#):
>
> We’ve reproduced the issue. We’re trying to find the best solution across all our platforms.
> 
> Edit: This will be fixed in 1.08.09 which will be released early August.

Awesome, thanks for the info.

---

<div class="post-metadata">

**Author:** ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)\
**Post date:** [July 27, 2016, 3:52am UTC](https://qa.fmod.com/t/sound-readdata-blocking-call-on-error-when-streaming/12582/9 "2016-07-27T03:52:06Z")

</div>

Updated post
