Author Topic: StreamCreateUrl - occasional Timeout  (Read 180 times)

ujr

  • Posts: 34
StreamCreateUrl - occasional Timeout
« on: 17 May '22 - 09:26 »
Hi,

I'm using StreamCreateUrl to download/stream some mp3 file. It usually works - but every now and then, sometimes more, sometimes less often, the call to StreamCreateUrl (actually Bass.StreamCreateUrl via C#) returns a stream ID of 0, and BASS_ErrorGetCode returns BASS_ERROR_TIMEOUT.

The environment is rather restricted by firewall rules, so it seems this should be the cause, because I never had such problems before. However, I would like to have some reasoning.

Is there any way to confirm that the timeout happens during connection? What does StreamCreateUrl do until timeout? It would be great if I could reproduce the error with simple socket calls (TCPClient), because I'm told: "But it works with Edge"   ::)

I realized, that the StreamCreateUrl returns with timeout after 10 seconds, although the configuration value BASS_CONFIG_NET_TIMEOUT has not been touched and is actually 5000 when queried by BASS_GetConfig. Where do the 10 seconds come from? Should it try twice?

Thank you!

Best regards

Ian @ un4seen

  • Administrator
  • Posts: 24418
Re: StreamCreateUrl - occasional Timeout
« Reply #1 on: 17 May '22 - 14:20 »
It sounds like the URL may have been a playlist? In that case, the BASS_CONFIG_NET_TIMEOUT setting applies to each entry in the playlist, eg. if there are 2 entries and both timeout then the BASS_StreamCreateURL call will take twice as long.

If other software on the same system is able to open the URL without timing-out then it may be that that software has a higher timeout (a browser is very likely to). You could try raising the BASS_CONFIG_NET_TIMEOUT setting and see if that helps.

ujr

  • Posts: 34
Re: StreamCreateUrl - occasional Timeout
« Reply #2 on: 23 May '22 - 16:41 »
Hi Ian,

thank you for helping!

The URL refers to one single mp3 file, no playlist actually. There shouldn't be any noticable timeout (if there's no timeout, playback is started immediately) - I may try to increase the value, but in fact, a larger delay wouldn't be a good workaround.

What is BASS_StreamCreateURL calling under the hood? Just OS specific single connection calls?

Ian @ un4seen

  • Administrator
  • Posts: 24418
Re: StreamCreateUrl - occasional Timeout
« Reply #3 on: 23 May '22 - 18:00 »
What platform is this happening on? If the URL isn't a playlist then another possibility on Linux/Android is that it's the DNS lookup (getaddrinfo call) that's taking the time. BASS currently always waits for that to finish (successfully or unsuccessfully) before timing-out on those platforms, so a BASS_StreamCreateURL call could take longer than the timeout setting then.

Perhaps the affected user could try changing their DNS servers (eg. to 8.8.8.8 or 1.1.1.1) and see if the problem still happens then?

ujr

  • Posts: 34
Re: StreamCreateUrl - occasional Timeout
« Reply #4 on: 24 May '22 - 07:48 »
Yes! That's what occurred tonight to me as well!

System is Windows, everything (client, server, DNS) inside a "heavily subnet'ed" LAN.

10 seconds sound like a reasonable DNS timeout. Would BASS_StreamCreateURL ignore OS DNS cache? This could explain a lot.

First I thought I could just use the IP, but the URL is https. Is there any way to ignore certificate errors?

Next try for me is to change the hosts file if that has any influence.

Ian @ un4seen

  • Administrator
  • Posts: 24418
Re: StreamCreateUrl - occasional Timeout
« Reply #5 on: 24 May '22 - 13:11 »
System is Windows, everything (client, server, DNS) inside a "heavily subnet'ed" LAN.

DNS lookups are cancelled by BASS after the timeout expires on Windows, so what I wrote above about waiting for that on Linux/Android wouldn't apply in your case.

Another thing that could cause BASS_StreamCreateURL to take longer than the timeout setting is HTTP redirections. Redirections don't restart the timeout but each redirect won't be limited by previous ones. For example, if the timeout is 5s and it takes 3s to open the original URL then the redirected URL will still get 5s (not 2s) to open, ie. it could take 8s in total. If there's another redirect then that will only be opened if the timeout hasn't already been exceeded.

Would BASS_StreamCreateURL ignore OS DNS cache? This could explain a lot.

The DNS cache should be used. You can try capturing the network traffic with Wireshark to check this, eg. try opening the same URL twice and see if there's a DNS query each time.

First I thought I could just use the IP, but the URL is https. Is there any way to ignore certificate errors?

BASS does already ignore certificate errors, but note you won't be able to use the IP address if the server depends on a hostname to determine what content to serve.

ujr

  • Posts: 34
Re: StreamCreateUrl - occasional Timeout
« Reply #6 on: 10 Jun '22 - 09:31 »
First I thought I could just use the IP, but the URL is https. Is there any way to ignore certificate errors?

BASS does already ignore certificate errors

From my experience this is not the case - at least on Windows via bass.net (I would assume, that Bass.Net just passes the calls to Bass), as long as the certificate cannot be validated by the OS, Bass.BASS_StreamCreateURL returns 0 while Bass.BASS_ErrorGetCode() gives BASSError.BASS_ERROR_UNKNOWN. It works as soon as the self signed root certificate is imported.

At the moment it looks like we may have fixed the problem: Wireshark capture logs revealed, that the system in this specific environment receives replies from DNS in milliseconds. In the majority of (if not all) attempts to play the file immediately after our software has been started, and at certain time intervals (we haven't tried to find out how often actually), the OS tried to access ctldl.windowsupdate.com which appears to block BASS_StreamCreateURL. The unpleasant thing is, that the DNS replies with an external IP, but the firewall prevents access. So BASS_StreamCreateURL timesout eventually.

ctldl.windowsupdate.com is used to update some Windows internal certificate lists. Unfortunately, this cannot be circumvented by overriding the IP with the hosts file. However, it seems the certificate updates can be disabled altogether by a small change in registry, eg with this PowerShell snippet:
Code: [Select]
Set-ItemProperty -Path 'HKLM:\Software\Policies\Microsoft\SystemCertificates\AuthRoot' -Name DisableRootAutoUpdate -Value 1

So far, the timeout has not occurred again - fingers crossed...

Ian @ un4seen

  • Administrator
  • Posts: 24418
Re: StreamCreateUrl - occasional Timeout
« Reply #7 on: 10 Jun '22 - 12:29 »
From my experience this is not the case - at least on Windows via bass.net (I would assume, that Bass.Net just passes the calls to Bass), as long as the certificate cannot be validated by the OS, Bass.BASS_StreamCreateURL returns 0 while Bass.BASS_ErrorGetCode() gives BASSError.BASS_ERROR_UNKNOWN. It works as soon as the self signed root certificate is imported.

That's strange, self-signed certificates should be fine. I tried setting one up just now, and the hosted files were indeed playable with BASS_StreamCreateURL. Can you provide a troublesome URL to have a look at? You can PM it to me if it's private. Please also confirm that the latest BASS version is being used with BASS_GetVersion.

Good to hear that you've found the cause of the timeouts and a solution.

ujr

  • Posts: 34
Re: StreamCreateUrl - occasional Timeout
« Reply #8 on: 10 Jun '22 - 14:59 »
Hi,

oh - for some reason the application was still using 2.4.14! Now with 2.4.16, the URL is streamed even if the certificate cannot be acknowledged 8)

It's strange for me, because I thought that when I started to investigate this problem I had updated the library in order to be sure it's not due to an old version. Need to check what happened...
Edit: version before this "update" was even older (2.4.13) - however, I cannot see where I got this 2.4.14 from... maybe mismatched two downloads on different systems - not too important for now  :)

Thank you so much for your help!!!
« Last Edit: 10 Jun '22 - 15:09 by ujr »