Bug 5830 - Connection timeout with many plugins installed
: Connection timeout with many plugins installed
Status: RESOLVED FIXED
Product: Logitech Media Server
Classification: Unclassified
Component: Misc
: 7.0
: PC Other
: P2 normal (vote)
: ---
Assigned To: Squeezebox QA Team email alias
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-10-17 09:27 UTC by Erland Isaksson
Modified: 2007-10-22 13:48 UTC (History)
1 user (show)

See Also:
Category: ---


Attachments
server.log after startup when the problem occurs (7.41 KB, text/plain)
2007-10-17 09:30 UTC, Erland Isaksson
Details
server.log file with some more debugging enabled (129.17 KB, text/plain)
2007-10-19 21:44 UTC, Erland Isaksson
Details
server.log file from svn #13997 (113.57 KB, text/plain)
2007-10-21 21:40 UTC, Erland Isaksson
Details
server.log with only network.asynchttp = DEBUG (10.83 KB, text/plain)
2007-10-22 10:05 UTC, Erland Isaksson
Details
Sample plugin that can be used to reproduce the problem. (1.38 KB, application/octet-stream)
2007-10-22 12:13 UTC, Erland Isaksson
Details
Updated sample plugin that reproduces the problem with an add_task call (1.44 KB, application/octet-stream)
2007-10-22 13:18 UTC, Erland Isaksson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Erland Isaksson 2007-10-17 09:27:47 UTC
I seem to get connection timeout when I have many plugins installed. I think the problem might be related to that the plugins perform some stuff at startup that might take some time.

I'll attach the complete server.log file after startup, but here is the timeout related messages. The problem disappears if I disable a few plugins.

[18:25:29.7023] Slim::Networking::Async::_connect_error (273) Failed to connect: 
[18:25:29.7031] Slim::Networking::Async::_async_error (370) Error: [Connect timed out]
[18:25:29.7035] Slim::Networking::Async::HTTP::_http_error (262) Error: [Connect timed out]
[18:25:29.7038] Slim::Networking::SimpleAsyncHTTP::onError (183) Failed to connect to http://www.squeezenetwork.com/ (Connect timed out)
[18:25:29.7041] Slim::Web::Settings::Server::Wizard::__ANON__ (43) Couldn't connect to squeezenetwork.com - do we need a proxy?
Connect timed out
[18:25:29.8011] Slim::Networking::Async::_connect_error (273) Failed to connect: 
[18:25:29.8019] Slim::Networking::Async::_async_error (370) Error: [Connect timed out]
[18:25:29.8021] Slim::Networking::Async::HTTP::_http_error (262) Error: [Connect timed out]
[18:25:29.8025] Slim::Networking::SimpleAsyncHTTP::onError (183) Failed to connect to http://update.slimdevices.com/update/firmware/7.0/jive.version (Connect timed out)
[18:25:29.8028] Slim::Utils::Firmware::downloadAsyncError (468) Warning: Firmware: Failed to download http://update.slimdevices.com/update/firmware/7.0/jive.version (Connect timed out), will try again in 10 minutes.
Comment 1 Erland Isaksson 2007-10-17 09:30:23 UTC
Created attachment 2275 [details]
server.log after startup when the problem occurs

This is the server.log file after startup when the problem occurs, you should be able to see the times in the log.

I guess we could blame the plugins, but I think SqueezeServer should be able to handle plugins that needs to do some stuff that takes a few seconds at SqueezeServer startup.
Comment 2 KDF 2007-10-17 19:58:46 UTC
it's probably not plugin relates.  Squeezenetwork is seeing some timeouts for certain regions.  Upgrades are in progress.
Comment 3 Erland Isaksson 2007-10-17 20:55:39 UTC
(In reply to comment #2)
> it's probably not plugin relates.  Squeezenetwork is seeing some timeouts for
> certain regions.  Upgrades are in progress.
> 

Well I think it is, because if I disable some of my plugins it works perfectly and 
when I enable them again directly afterwards and restart SqueezeCenter I get the message. 
It's very easy to reproduce on my machine, with only standard plugins which start pretty quick
everything works as it should, with my own plugins enabled which take a bit longer to startup
it fails.

Maybe the SqueezeNetwork requests are started before the plugins are loaded  and then 
it loads the plugin and if that takes to much time, the SqueezeNetwork request timeout 
even if SqueezeNetwork really is available ?
Comment 4 KDF 2007-10-17 22:25:04 UTC
Then you'll need to add more debug options.  Those logs show nothing other than SN timeouts.
Perhaps there is one that is making a blocked connection, try narrowing it down.
Comment 5 Erland Isaksson 2007-10-19 21:44:56 UTC
Created attachment 2293 [details]
server.log file with some more debugging enabled

I enabled the network.* and server.* debugging flags in this server.log file, let me know if you want me to enable some other flags.
Comment 6 KDF 2007-10-20 12:23:10 UTC
Thanks Erland,

did you do this with the latest from SVN.  I saw that Andy added a number of dns related changes on friday, so that might have an effect here.
Comment 7 Erland Isaksson 2007-10-20 21:09:50 UTC
(In reply to comment #6)
> Thanks Erland,
> 
> did you do this with the latest from SVN.  I saw that Andy added a number of
> dns related changes on friday, so that might have an effect here.
> 

The latest log attached was with svn 13941
Comment 8 Andy Grundman 2007-10-21 07:52:13 UTC
Yes there are some async requests started during init that are not processed until later, so they can time out if other init things take too long.  Perhaps anything in init should be started by a timer instead so they don't run until after init.  I'll look at this.
Comment 9 Andy Grundman 2007-10-21 08:04:45 UTC
Should be fixed in change 13984.
Comment 10 Erland Isaksson 2007-10-21 21:38:44 UTC
This correction didn't solve the problem for me, the problem remains in my setup. I tried to make a sample plugin that just made a sleep in it's initPlugin, but I wasn't able to reproduce the problem this way so I'm not sure exactly what the problem is.
Comment 11 Erland Isaksson 2007-10-21 21:40:41 UTC
Created attachment 2299 [details]
server.log file from svn #13997
Comment 12 Andy Grundman 2007-10-21 22:34:55 UTC
Can you trim down your debug settings to only include network.asynchttp?  There's too much junk to sort out what your problem is.
Comment 13 Erland Isaksson 2007-10-22 10:05:30 UTC
Created attachment 2301 [details]
server.log with only network.asynchttp = DEBUG
Comment 14 Andy Grundman 2007-10-22 10:37:41 UTC
Hmm, are you sure you are running the very latest code?  These:

[19:02:28.2971] Slim::Networking::SimpleAsyncHTTP::_createHTTPRequest (105) GETing http://update.slimdevices.com/update/firmware/7.0/jive.version
[19:02:28.3046] Slim::Networking::SimpleAsyncHTTP::_createHTTPRequest (105) GETing http://www.squeezenetwork.com/api/v1/time

Should now not occur until after "SqueezeCenter done init".

Check the file Slim::Networking::SqueezeNetwork and look for this in init():

        # Any async HTTP in init must be done on a timer
        Slim::Utils::Timers::setTimer(
                undef,  
                time(),
                sub {
                        $http->get( $timeURL );
                },
        ); 

Comment 15 Erland Isaksson 2007-10-22 11:16:40 UTC
(In reply to comment #14)
> Should now not occur until after "SqueezeCenter done init".
> 
> Check the file Slim::Networking::SqueezeNetwork and look for this in init():
> 
>         # Any async HTTP in init must be done on a timer
>         Slim::Utils::Timers::setTimer(
>                 undef,  
>                 time(),
>                 sub {
>                         $http->get( $timeURL );
>                 },
>         ); 
> 

I'm running svn 13997, and that code exist in the end of the init() function in Slim::Networking::SqueezeNetwork
Comment 16 Andy Grundman 2007-10-22 11:25:56 UTC
Hmm, do any of those 3rd party plugins call idle() or idleStreams() during init?
Comment 17 Erland Isaksson 2007-10-22 12:12:06 UTC
(In reply to comment #16)
> Hmm, do any of those 3rd party plugins call idle() or idleStreams() during
> init?
> 

Yes, one of them calls idleStreams. But I tried to remove those calls and the SqueezeNetwork and jive connections still fails. However, I also tested to insert a log message in the idleStreams function and it seems that it is still called indirectly because the plugin also calls Slim::Utils::Misc::readDirectory which calls idleStreams.

I can reproduce the problem with a simple sample plugin that sleeps a bit and calls idleStreams during initialization.
Comment 18 Erland Isaksson 2007-10-22 12:13:00 UTC
Created attachment 2302 [details]
Sample plugin that can be used to reproduce the problem.
Comment 19 Andy Grundman 2007-10-22 12:22:21 UTC
OK, guess I need to find another way around this.  Probably will create a flag for "init mode" and have idle and idleStreams be a noop during init.
Comment 20 Andy Grundman 2007-10-22 12:52:11 UTC
OK I think it should really be fixed this time. :)  Change 14014.
Comment 21 Erland Isaksson 2007-10-22 13:17:26 UTC
I'm sorry, but it still doesn't work. I think the problem is that I do some operations in initPlugin but I also call Slim::Utils::Scheduler::add_task at the end of initPlugin because some operations can't be executed until all plugins have been loaded. It seems like your fix corrects the case when idleStreams are called within initPlugin, but it doesn't cover the case when it's called with in the function specified in add_task.
Comment 22 Erland Isaksson 2007-10-22 13:18:18 UTC
Created attachment 2303 [details]
Updated sample plugin that reproduces the problem with an add_task call
Comment 23 Andy Grundman 2007-10-22 13:28:16 UTC
But nothing in Scheduler is run until after init is done so this should not be a problem.  Putting a sleep in a scheduled task is just stupid!  Are your plugins blocking the server for a large amount of time after init?  If so, why?  You should only block during the init phase (or only do it with a child process i.e. scanner.pl).
Comment 24 Erland Isaksson 2007-10-22 13:44:27 UTC
I need to do some things after initPlugin beacuse there are dependencies to other plugins. So if I call PluginManager->enabledPlugins inside initPlugin I won't get all plugins, but if I call it inside the function specified with add_task it works because then it isn't executed until all plugins have been loaded.

The operations executed are some XML parsing and some database table updates. The operations executed in the add_task function might take a few seconds, maybe maximum 10 seconds.

The sample plugin I attached is a bit extreme in that it sleeps for 20 seconds during initPlugin and 20 seconds after initPlugin, the times are shorter in the real plugins.
Comment 25 Andy Grundman 2007-10-22 13:48:09 UTC
There is nothing I can do if plugins are going to block for that amount of time.  I still consider this issue fixed.

Also, I was just looking at your CustomBrowse plugin.  Please don't perform synchronous HTTP requests within SC (using SOAP::Lite, etc).  You should avoid blocking the server at all costs.