For some reason an icecast client known as BUTT (Broadcast Using This Tool) simply refused to work with Streampusher.
BUTT works normally with Liquidsoap’s harbor, so I thought it must have be something wrong with my code.
I use a small ruby script to authenticate the harbor, like this:
When I tried to connect using BUTT, it would simply hang. I decided to try to compile BUTT to try to debug, but I was unable to get it to compile.
I started reading icecast.cpp, trying to find anything related to some sort of timeout.
This code looked a bit suspicious.
What I took from this is that
sock_recv seems to be timing out.
The RECV_TIMEOUT constant is set to 1000ms.
After some experimenting with timing the ruby script, I found that it always took longer than 1000ms to finish running. If I changed the script to run against a local test server, it completed under 1000ms and BUTT connected just fine!
But connecting against the real server always took 1000ms. How can I make it run faster? I tried some things like using the script without bundler, using built in libraries instead of Gems, but this didn’t really help. Was my auth server too slow?
Looking at my rails logs, the auth action itself only takes 140ms. Does it really take another 800ms or so for the http request to go across the internet?
All the ruby script does is make an http request and parse the json response. I decided to test the request using curl. With curl it was much faster than ruby.
Perhaps I could rewrite the auth script in bash. But how could I parse json in bash? Turns out jq is a great tool for this job.
With the bash script the request completes under 1000ms and now BUTT works with Streampusher just fine.