PDA

View Full Version : Strange error from SimpleAsyncHTTP ?



erland
2010-05-18, 23:04
I get the following error from SimpleAsyncHTTP when I try to download an icon from my MythTV box.

==============
Error reading headers: Server closed connection without sending any data back at /media/disk2/squeezecenter/7.5/server/CPAN/Net/HTTP/Methods.pm line 306.
...propagated at /media/disk2/squeezecenter/7.5/server/CPAN/Net/HTTP/NB.pm line 32.
=============

I'm calling it like this:


my $iconurl = 'http://172.16.0.114:6544/Myth/GetChannelIcon?ChanId=2307';
my $iconid = '2307';

my $cachedir = $serverPrefs->get('cachedir');
my $icondir = catdir( $cachedir, 'MythTVIcons' );
my $iconpath = catfile( $icondir, $iconid );

my $http = Slim::Networking::SimpleAsyncHTTP->new(
sub {},
sub {
my $http = shift;
my $error = $http->error;
$log->error( "$error" );
},
{
saveAs => $iconpath,
iconurl => $iconurl,
iconid => $iconid,
},
);

my %headers;

if ( -e $iconpath ) {
$headers{'If-Modified-Since'} = time2str( (stat $iconpath)[9] );
}

$http->get( $iconurl, %headers );


The strange thing is that it works sometimes and sometimes not.
Have I missed something obvious ?

If you want to see the code in the full context, it's available here:
http://erlandplugins.googlecode.com/svn/MythTV/trunk/src/Plugin.pm
(Look for the "cacheIcon" function)

I don't think I saw these kind of messages earlier with an earlier 7.x release, it was probably during 7.4 beta when I run this code last.

Note, this might all be caused by something on the MythTV side, but it seems to work perfectly all the time when I access the same URL from a web browser.

andyg
2010-05-19, 04:26
On May 19, 2010, at 2:04 AM, erland wrote:

>
> I get the following error from SimpleAsyncHTTP when I try to download an
> icon from my MythTV box.
>
> ==============
> Error reading headers: Server closed connection without sending any
> data back at
> /media/disk2/squeezecenter/7.5/server/CPAN/Net/HTTP/Methods.pm line
> 306.
> ...propagated at
> /media/disk2/squeezecenter/7.5/server/CPAN/Net/HTTP/NB.pm line 32.
> =============

What does a network.asynchttp log show?

erland
2010-05-19, 12:58
On May 19, 2010, at 2:04 AM, erland wrote:

>
> I get the following error from SimpleAsyncHTTP when I try to download an
> icon from my MythTV box.
>
> ==============
> Error reading headers: Server closed connection without sending any
> data back at
> /media/disk2/squeezecenter/7.5/server/CPAN/Net/HTTP/Methods.pm line
> 306.
> ...propagated at
> /media/disk2/squeezecenter/7.5/server/CPAN/Net/HTTP/NB.pm line 32.
> =============

What does a network.asynchttp log show?

server.log with network.asynchttp enabled is attached to this post.
You will find the error around the middle of the file.

I wonder if there could be some issue with launching multiple async requests in a short time span ?

andyg
2010-05-19, 13:04
On May 19, 2010, at 3:58 PM, erland wrote:

>
> andyg;548873 Wrote:
>> On May 19, 2010, at 2:04 AM, erland wrote:
>>
>>>
>>> I get the following error from SimpleAsyncHTTP when I try to download
>> an
>>> icon from my MythTV box.
>>>
>>> ==============
>>> Error reading headers: Server closed connection without sending any
>>> data back at
>>> /media/disk2/squeezecenter/7.5/server/CPAN/Net/HTTP/Methods.pm line
>>> 306.
>>> ...propagated at
>>> /media/disk2/squeezecenter/7.5/server/CPAN/Net/HTTP/NB.pm line 32.
>>> =============
>>
>> What does a network.asynchttp log show?
>
> server.log with network.asynchttp enabled is attached to this post.
> You will find the error around the middle of the file.
>
> I wonder if there could be some issue with launching multiple async
> requests in a short time span ?

It could be, maybe it's overloading the MythTV server? A tcpdump might provide more info. Or maybe there is some logging on the MythTV server side?

erland
2010-05-19, 22:10
On May 19, 2010, at 3:58 PM, erland wrote:

>
> server.log with network.asynchttp enabled is attached to this post.
> You will find the error around the middle of the file.
>
> I wonder if there could be some issue with launching multiple async
> requests in a short time span ?

It could be, maybe it's overloading the MythTV server? A tcpdump might provide more info. Or maybe there is some logging on the MythTV server side?


There is nothing in the MythTV log, but I did some experiments.

I tried changing my code so the async http requests are executed in sequence, issuing the next request when I got the answer from the previous one. This seems to work correctly as far as I can see, so with this solution everything works. Which basically means that the problem is solved. I've no idea if it has to do with decreased load on MythTV or some problem in SBS code when issue multiple async http requests in parallel.

Before trying to run them in sequence I also tried inserting a sleep between the requests to decrease the load on MythTV, the result was that it didn't work. I got time out messages. I suspect it might have to do with the fact that my thread is locked up doing sleep when it ought handle the responses from earlier async http requests.

I know it's a really bad idea to lock up a thread with sleep, I only did this to see if it made any difference since it was easy to test.

peterw
2010-05-19, 22:48
Why not test the concurrency theory by requesting a highly available icon like an akamaized image or image on a major, fast web site like google or yahoo?