None of my iDevices can read my iTunes library after an hour of availibility. When I first start iTunes I can read the library, but after about 30 minutes my iPad's and iPhones can no longer access the library. I see it in the shared list, but no access.

None of my iDevices can read my iTunes library after about 30 minutes. My iDevices lose connection to my library and I have to do one of the three following things in iTunes to regain connectivity: 1. Restart iTunes 2: Stop / Start Home Services 3: Start playing a song.

I'ts as if iTunes goes into a background or sleep mode. During the loss of connectivity my iDevices show that there's a library shared, but I cannot connect to it.

iPhone 4, iOS 5

Posted on May 13, 2012 1:34 PM

Reply
221 replies

Jun 4, 2012 2:03 PM in response to aut0maticdan

Well after my anouncement yesterday I hope you will all welcome me back in the fold of having this problem. I had to log out and log back in and now everything is back to normal (broken).


aut0maticdan

Very cool solution. I should have looked into this further. I figured it was still responding to the port but just timed out on the query to get stuff from the server. Either way that is a nice solution that should not need to exist 🙂.

Jun 4, 2012 2:19 PM in response to cendrizzi

That's correct. You could redirect the output of the script to the log:


~/Documents/homesharing-keepalive.rb > ~/Desktop/homesharing_out.txt 2>&1


Unfortuneately I was also printing successful connections to the screen in the previous version, so I don't know how many exactly, but I do know at least one was in my terminal scroll history.


I actually just made an adjustment based on something the OP said. If just playing a song wakes it up enough, maybe I don't need to restart itunes. I'm instead trying with just asking itunes to return its state:


osascript -e 'tell application "iTunes" to player state as string'


If this works, it would be a much more elegant solution. In fact, I wouldn't even need to test the port, I could just ask for its state every five seconds with a bash one-liner:


while true; do osascript -e 'tell application "iTunes" to player state as string'; sleep 5; done


That would mean itunes would never get the chance to go to sleep. I'll let you know how it goes.

Jun 4, 2012 3:09 PM in response to aut0maticdan

After doing a little digging, I don't think Sonos uses iTunes sharing of any sort. It scans the files on your hard drive and shares them itself.


Unfortunately, I don't even have a windows instance to test scripts in. I'm sure with the basic idea any windows scripter could pretty easily write something up. If my current test works, its going to get a lot easier.

Jun 5, 2012 8:22 AM in response to cendrizzi

OK, so the simplest explanation is that there is a period of time where the port is still accessible but home sharing is still not fuctioning properly.


I still don't understand why stopping the script would resolve it. For over a week, I was hitting the port once a second with no ill effects. My thinking was opening the socket regularly would keep it alive, but it didn't do the job.


Anyway, if you guys are feeling like testing something new, try copy/pasting this into a terminal:


while true; do osascript -e 'tell application "iTunes" to player state as string'; sleep 30; done


It just requests the status from itunes every 30 seconds and prints it to the terminal. Since it does not rely on testing the port, you may find more success. I haven't finished testing it yet, but it can't hurt for you to try.

Jun 5, 2012 8:39 AM in response to SilverSevens

I tried your program last night and found the same as above.


Your script gave me a message about restarting iTunes as soon as I started it, and i could then connect to Home Sharing. After a couple of hours of idle though, the script was giving no messages about restarting iTunes, but I couldn't access it. Whilst the Apple TV was still spinning and saying connecting, I pressed CTRL-c to stop the script and the Apple TV instantely connected.


I don't know Ruby, so am just guessing... Is your script opening the port then just keeping it open? I didn't see any code to close the port, but as I said, I'm not familiar with Ruby. Stopping the script closes the port which causes iTunes to sit up and take notice, starting Home Sharing working again? Perhaps opening and closing the port every now and again will keep iTunes alive if this is the case...


I'm likely wrong though!

Jun 5, 2012 9:27 AM in response to MIster Volition

doh! good call! I made some adjustments to the script when I was cleaning up and posting it and removed the close! The loop I have running at home does not have this bug.


I confirmed with netstat that it is definitely the case that the script is holding onto the socket. At some point, home sharing is going to reach max connections/file descriptors and will not accept new ones. Sorry about that guys, I posted the fix and confirmed that it no longer holds on to the socket but still detects when its down.


you can just rerun the install script and then launch again:


curl http://djw.s3.amazonaws.com/homesharing-keepalive.rb > ~/Documents/homesharing-keepalive.rb && chmod +x ~/Documents/homesharing-keepalive.rb


###


~/Documents/homesharing-keepalive.rb

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

None of my iDevices can read my iTunes library after an hour of availibility. When I first start iTunes I can read the library, but after about 30 minutes my iPad's and iPhones can no longer access the library. I see it in the shared list, but no access.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.