jasonmc / forked-daapd

A re-write of the firefly media server (mt-daapd). It's released under GPLv2+. Please note that this git repository is a mirror of the official one at git://git.debian.org/~jblache/forked-daapd.git
http://blog.technologeek.org/2009/06/12/217
GNU General Public License v2.0
328 stars 45 forks source link

Feature request: keepalive / timeout in forked-daapd.conf #19

Open Max905 opened 13 years ago

Max905 commented 13 years ago

After a certain length of time (30 minutes or so, I think), a DAAP stream will time out. For example, pause a stream playing via Rhythmbox or Banshee. Attempt to resume playback 30 minutes later. It will fail. The only way to resume playback is to disconnect from the DAAP server and reconnect. At that point, the prior playback position has been lost.

Is it possible to add a keepalive or timeout that could be controlled via a parameter in forked-daapd.conf?

peterjc commented 13 years ago

This might require a client fix instead/as well.

Could you ask Rhythmbox or Banshee if they make any attempt to tell the server they are still using the connection?

Max905 commented 13 years ago

I take your point, but FWIW iTunes exhibits the same behaviour. I get the feeling Apple would be less than accommodating.

peterjc commented 13 years ago

Should be fixed in forked-daapd v0.13 http://blog.technologeek.org/2011/03/12/465

ldesgrange commented 13 years ago

Hi everyone, when playing music with iTunes 10.2.1 on a Mac, it gets disconnected from forked-daapd after 30 minutes (exactly 30 minutes from the moment iTunes is connected to the playlist, no matter if I play music or not).

I've tried with forked-daapd 0.14-1 and 0.15-1 on debian. I didn't had the problem on 0.12 and I don't remember if I have used 0.13. It seems that I don't have the problem when playing with Rythmbox 0.13.1 on Ubuntu (but I haven't checked seriously).

The only message I see in forked-daapd log file is: httpd: Connection failed; stopping streaming of file ID XXX (which is the same message I have when I skip a song in iTunes)

bobcote commented 13 years ago

ldesgrange is right. I tried Forked-Daapd 0.14 on a D-Link DNS-323 with Alt-F Firmware and exactly 30 minutes after I start playing music on Itunes 10.2.1 on a Mac the connection drops, even in the middle of playing a song.

bobcote commented 13 years ago

I wrote to Julien Blache (Forked-Daapd author) and he said that he is aware of the bug, but that he doesn't have time at this moment to resolve a bug that needs each time 30 minutes to reproduce.

ldesgrange commented 13 years ago

I did a tcpdump to check if something specific was happening. Here is what I did:

On the tcpdump I only see iTunes properly closing the connection: iTunes -> forked-daapd: [FIN, ACK] forked-daapd -> iTunes: [FIN, ACK] iTunes -> forked-daapd: [ACK]

I don't know, maybe while connected iTunes is waiting for some "keep alive" messages (even while already playing music from the shared library). H.T.H.

By the way I'm realizing that the problem we are discussing is a bit different from the original one (which I remember used to happen to me before I upgrade forked-daapd and get this disconnection instead), sorry for that.

vof commented 13 years ago

I am using forked 0.14 and see this problem with iTunes on both Windows and OS X. I do not see it with Rhythmbox on ubuntu. I rarely pause so have never seen it while paused. It always happens exactly 30 mins after starting to stream in iTunes. I can stream for hours with Rhythmbox. Log shows same basic message as others have reported.

bobcote commented 13 years ago

Updated to 0.16. Still has the same annoying problem. I can't believe that with so many installations on commercial NAS (and vast majority of users mostly using iTunes) there is not much of an outcry and that nobody has already solved this bug. I mean, there is surely tons of people having this annoying problem, it should be top priority.

ldesgrange commented 13 years ago

@bobcote: afaik forked-daapd is nearly not used in commercial NAS, most of them are using mt-daapd (which didn't had this timeout issue last time I used it). I'm afraid that we are not so many using it, forked-daapd is more of a "pet project" and I don't think there are enough contributors with enough time to tackle this problem quickly (considering that you need at least 30 minutes to test each time as you said earlier). If you have any knowledge to solve this problem I'm sure everybody here will be happy ;-).

bobcote commented 13 years ago

Maybe I'm wrong. I was with the impression that when last year iTunes 10 temporarily broke compatibility with mt-daapd/firelfy that QNAP and Synology had packaged Forked-Daapd as a solution, which could have lead to many people with the same problem we have here. But as I don't have those NAS (I have a D-Link DNS-323) and had this impression only by reading all the forum posts at those companies websites, I could possiibly be wrong indeed. I really thought Forked-daapd was more "serious" and was the de facto new daap server privileged by NAS makers.

ldesgrange commented 13 years ago

I don't know, maybe you are right, but since Apple released a fixed version of iTunes 10 quite quickly I thought NAS makers didn't switched to forked-daapd, maybe if they did, at that time forked-daapd didn't had this issue either and they are still using that old version… I haven't seen people complaining about this bug on NAS (but I had only a quick look so maybe you have found some). Could be interesting to know how many NAS makers use forked-daapd by default or if they provide it as an alternative DAAP server only).

iamdb commented 13 years ago

I have a QNAP NAS that I'm running this on and it came with mt-daapd. I had to replace that with forked-daapd.

I'm having this same problem, however. Exactly at the 30 minute mark iTunes drops the connection. I didn't have this problem with mt-daapd and I don't have the problem when playing through the Remote app. I found a tweet from February by someone who was looking into the problem and he found a hardcoded maximum in a file. He said he'd provide more details so hopefully that will help solve this issue.

CraigMarkwardt commented 12 years ago

I confirm this problem still exists in forked-daapd 0.18. iTunes 9.2.1 closes the connection exactly 30 minutes after connecting, regardless of activity. (i.e. I can be playing a song or paused during the 30 minutes, it doesn't matter) UPDATE 2011-08-24: I believe I have fixed the timeout problem. Changes can be found on this fork: https://github.com/CBGoodBuddy/forked-daapd The two commits solve a 30 minute time-out problem and also enable dynamic updating of the music listing whenever you add using files to your server. Before you had to disconnect iTunes from the server, now the new music should show up within about ten seconds. I contacted the author Julien Blache and he seemed receptive to include one or both patches for the future.

bobcote commented 12 years ago

Good job CBGoodBuddy! I can't unfortunately test as I rely on the version included in Alt-F firmware for D-Link DNS-323, which is ARM based, so patches will need to be backported to the last arm compatible version.

kazdegroot commented 12 years ago

Great work! It doesn't seem to be completely fixed though. With both patches applied iTunes happily kept playing for hours while forked-daapd was scanning my library and adding new songs every few seconds. After it finished, it eventually kicked me off and has continued to do so every +-30 minutes. (Haven't timed it, though) Tested with iTunes 10.5(b)

CraigMarkwardt commented 12 years ago

Well, that's frustrating. Sadly, I can't replicate the problem with iTunes 9 or 10. Can you tell if the time out is 30 minutes or 25 minutes? The new code ensures that iTunes gets some kind of activity at least every 25 minutes, but maybe that's too infrequent. (one possibility is something else is timing out, like your router)

If you have access to the code, it may be worth trying to change http_daapd.c line 64,

define DAAP_UPDATE_TIMEOUT 1500

which is a 25 minute time out expressed in seconds, to something shorter, like,

define DAAP_UPDATE_TIMEOUT 60

which guarantees activity at least every minute.

I don't know what the real iTunes does....

kazdegroot commented 12 years ago

Rather than time the 25 minutes, I changed the line. First to 60, then to 120. On my computer (with lion and itunes 10.5) that causes a disconnect after respectively 60 and 120 seconds. On another computer I tried (snow leopard and iTunes 10.4) it's still going strong.

I don't have a lion/10.4 machine myself, but I'm going to have someone try that as well. If it's only 10.5, it might just be a (beta) bug in iTunes, though mt-daapd works fine.

CraigMarkwardt commented 12 years ago

OK, that's pretty weird. I'm not sure why forced activity would force-close the connection. I checked mt-daapd which uses exactly the same method (except 30 second time-outs).

I tested iTunes 9.2.1 and 10.4 on Snow Leopard. I don't have access to Lion yet.

Sounds like there is some new behavior in Lion.

Could you try a 30 second time-out just to see if that improves things? Also, if you can enable debug mode, that might give a little more information about the transactions. But, you will want to operate on a reduced music library, otherwise you will be overwhelmed with debug statements. (I usually test in debug mode with a different config file that points to a single album)

kazdegroot commented 12 years ago

I'll try the debug thing later, but I do have some new info, tried both 30 and 20 second timeouts and they fail. Had a friend try with lion/10.4 which gave no problems, so it seems to be a 10.5 beta problem.

CraigMarkwardt commented 12 years ago

It would be disappointing if the new version of iTunes changes the protocol, but I guess it wouldn't be the first time.

unsynchronized commented 12 years ago

I had this problem too; I solved it by removing some changes made in c70caad87e12357d7d912113f6a06b08d781afd1; also, I disabled autologout by setting the value for "msal" to 0.

Try this patch against head:

diff --git a/src/httpd_daap.c b/src/httpd_daap.c index 3017b3b..b1613c9 100644 --- a/src/httpd_daap.c +++ b/src/httpd_daap.c @@ -633,10 +633,8 @@ daap_reply_server_info(struct evhttp_request _req, struct evbuffer evbuf, char dmap_addint(evbuf, "apro", apro); / 12 _/ dmap_addstring(evbuf, "minm", name); / 8 + strlen(name) /

-#if 0 dmap_add_int(evbuf, "mstm", DAAP_SESSION_TIMEOUT); /* 12 */

kazdegroot commented 12 years ago

unsynchronized: That does solve the original problem, but it also disables CBGoodBuddy's awesome auto update feature which I've come to really enjoy.

Some further experiments showed iTunes ejecting when the forced update message was sent. I assumed it might have something to do with the new == old rev id on the iTunes side, so I added some hacky code to ensure it never sends a forced update with both being equal to the update method. And it seems to work. The library both auto updates and doesn't eject after either the update or the session timeout in iTunes 10.5. I couldn't find any daap documentation, so I don't know how many rules I'm breaking doing this, but it works for me.

Code I used:

Insert if (force == 1) ++db_rev; Before

    ur->session_id, ur->revision_number, db_rev, force);

On line 857 of httpd_daap.c

peterjc commented 12 years ago

Should be fixed in v0.19 http://blog.technologeek.org/2011/09/11/526

ldesgrange commented 12 years ago

Updated my box with 0.19, iTunes was not disconnected in the last few hours. Congrats guys! Thank you very much.

ldesgrange commented 12 years ago

It's still working on my box, auto-update is working too. @Max905 if everything is fine for you, maybe you should close this issue?

freultwah commented 12 years ago

Running 0.19 vanilla, just checked out a fresh copy. iTunes 10.4.1 works like a charm (though I am not seeing autoupdates), 10.5 still disconnects every 5 minutes, regardless of the value of 'msal'. So, does not work for me.

unsynchronized commented 12 years ago

Ditto here. It looks like the timed update response sent by update_refresh_cb() isn't making it very happy.

Two quick hacky fixes that worked for me are: 1) disabling this timer altogether (or bumping DAAP_VERSION_REFRESH) -- I assume this would break updates and; 2) incrementing current_rev before sending the mupd reply in update_refresh_cb.

Using #2 now; no problems yet, and updates seem to work; no long-term tests yet.

Issue #70 (https://github.com/jasonmc/forked-daapd/issues/70) argues that the number should increment whenever we see a directory rev change; this makes sense to me, as a long-term fix.

kazdegroot commented 12 years ago

I've had this problem for a while now, and I tried applying fix #2 to the GCD version of 0.19. It didn't seem to do any live updating like CBGoodBuddy's version does though; has anyone else tried the GCD version?

CraigMarkwardt commented 12 years ago

You folks are right. Something has changed about iTunes 10.5: it rejects "update" notifcations that 10.4 does not. If you update the db_rev each cycle, then you will incur the penalty of iTunes re-downloading your entire music library every so often, which is not optimal and terrible for mobile use. Someone needs to understand better what iTunes needs as a response.

mtmckenna commented 12 years ago

I think this issue describes the problem I had after updating to iTunes 10.5. iTunes would disconnect after being connected for five minutes. I decided to disable the refresh timer by commenting out line 897 on the 0.19 build: //ret = evtimer_add(&ur->timeout, &tv); . I think this is what unsynchronized mentioned as hacky fix 1.

So far, no disconnects. Hoping I didn't break something without realizing it.

pcace commented 12 years ago

Hey, im really new to programming... can you please describe me where exactly i have to make these changes, to fix the issue tha i get kicked out? -so in wich file is the "line 897" //ret = evtimer_add(&ur->timeout, &tv); ??

Thanks

mtmckenna commented 12 years ago

I commented out line 897 in src/httpd_daap.c of the .19 release (http://alioth.debian.org/~jblache/forked-daapd/forked-daapd-0.19.tar.gz). Hope that helps, but I also don't know if my workaround is a particularly good solution.

pcace commented 12 years ago

Hmm, i cannot see the line when i use the git-hub version (0.19gcd) any idea where i can find it there?

one more thing: what is the difference betwen the gcd version and the "normal"?

Pcace

kjmancuso commented 12 years ago

Since my library is mostly static, to get this working, I just disabled the timer completely. Here is the patch I used:

diff --git a/src/httpd_daap.c b/src/httpd_daap.c
index 7c424c3..cd4297c 100644
--- a/src/httpd_daap.c
+++ b/src/httpd_daap.c
@@ -1000,9 +1000,9 @@ daap_reply_update(struct httpd_hdl *h, struct evbuffer *evbuf, char **uri)
   dispatch_set_context(ur->timeout, ur);
   dispatch_source_set_event_handler_f(ur->timeout, update_refresh_cb);

-  dispatch_source_set_timer(ur->timeout,
-                           dispatch_time(DISPATCH_TIME_NOW, DAAP_UPDATE_REFRESH * NSEC_PER_SEC),
-                           DISPATCH_TIME_FOREVER /* one-shot */, 30 * NSEC_PER_SEC);
+//  dispatch_source_set_timer(ur->timeout,
+//                         dispatch_time(DISPATCH_TIME_NOW, DAAP_UPDATE_REFRESH * NSEC_PER_SEC),
+//                         DISPATCH_TIME_FOREVER /* one-shot */, 30 * NSEC_PER_SEC);

   /* Freeze the request */
   http_server_response_freeze(h->c, h->r, update_free_cb, ur);

GCD stands for grand central dispatch. His blog post explains it pretty adequately:

http://blog.technologeek.org/2010/07/17/330

pcace commented 12 years ago

Thanks! so is it right that i disable with this patch the ability to update the database completely while running forked-daapd? Is forked-daapd updateing the library when restrarting it?

And thanks for the explanation what GCD is!!!

Pcace

kjmancuso commented 12 years ago

Yes, this will disable dynamic updates. Restarting the daemon will update the database, at least it does for me (I just tried).

However, I had a stream playing all night using newest stable itunes.

pcace commented 12 years ago

This is GREAT!!! My Server is shutting down every night at 2.00 and boots at 8.00 - so it should update the database...

ill see ;)

Thanks!

karldyson commented 12 years ago

Hey,

I realise this doesn't fix the 5 minute disconnect problem, and only works if you have the relevant bits of kit, etc, but a workaround that seems to be working for me, is to define my Airport Express in the config, use 'Remote' on my iPhone, and cut out iTunes altogether.

Cheers.

pcace commented 12 years ago

Hey, what do you mean with "relevant bits of kit"? The workaround seems to fix the issue on my 0.19 build...

Pcace

freultwah commented 12 years ago

He means if you have Airport Express and an iPhone.

pcace commented 12 years ago

There IS a problem when using this patch above: i cannot control itunes after around half an hour - so i stay connected to the library, but i cannot click play for example (of course only in the forked-daapd library). in my house everybody has this problem! (4x osx, 1x windows, itunes 10.5)

Any Idea?

Thanks

ioquatix commented 12 years ago

I seem to have some similar issues with iTunes 10.5, every few minutes music stops with error message in log "httpd: Connection failed; stopping streaming of file ID xxxx".

skyy99 commented 12 years ago

Like ioquatix my iTunes 10.5 (141 build) disconnects every 5 mins in the middle of whatever is playing. This basically means forked-daapd ver. 0.19 isn't a solution that works with 10.5 (which is required now for iPhone 5 OS). :(

eviltrout commented 12 years ago

I'm also having the iTunes 10.5 issue. It's really frustrating as I can't listen to any of my music anymore :(

jochenstu commented 12 years ago

Same thing here, which is specially frustrating because I just switched from mt-daapd because it stopped working. Is there any alternative or can we expect a fix? :/

pcace commented 12 years ago

Hmm, somehow here it kind of workes: i can connect to my library, but i:

guictx commented 12 years ago

Just to confirm the same issue: after 5 minutes iTunes 10.5 stops and forked-daapd gives the httpd: Connection failed; stopping streaming of file ID...

I have forked-daapd 0.19 installed on a Ubuntu 11.10.

rdahlin commented 12 years ago

I too have the same timeoutproblem that has been described here. I recently bought a LaCie network storage for a friend and made a system upgrade on it (the last one had been released today) and I don't know what they base their iTunes server on but it works without any timeouts. Do anyone know what laCie bases their solution on ?

pcace commented 12 years ago

Any News about this bug?

Pcace