You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Kurt George Gjerde <ku...@intermedia.uib.no> on 2003/02/25 16:49:21 UTC

Help: Can't coerce GLOB to string...

Hi,

I get a "Can't coerce GLOB to string"-error for every new thread that is
started (mp2). I have no idea why this happens (or even what this error
actually means).

The module is included below (line producing the error is marked "ERROR
HERE"). Error happens for every new thread (on the first request).
When running ApacheBench  ab -c 3 -n 100 http://...  I get 3 errors and 97
OKs.

Very grateful if anyone care to look at this!

[Apache/2.0.43 (Win32) mod_perl/1.99_09-dev Perl/v5.8.0 DAV/2]


---------- Here's the module ----------

package MyApache::XSLTransformer;

use strict;
use warnings FATAL=>'all', NONFATAL=>'redefine';

use Apache::RequestRec ();
use Apache::RequestIO ();
use Apache::Const -compile => qw(OK);

use threads;
use threads::shared;

use XML::LibXML;
use XML::LibXSLT;

use APR::OS;

my $statRequestCount = 0;
my $statErrorCount = 0;


sub handler {
  my $r = shift;

  $statRequestCount++;

  $r->content_type('text/html');

  my $documentFilename = $ENV{SCRIPT_FILENAME};
  my $stylesheetFilename = $r->dir_config("xslTransformer_stylesheet");

  return 404 unless -e $documentFilename;

  my $xmlParser   = XML::LibXML->new();
  my $xsltParser  = XML::LibXSLT->new();

  ### PARSE DOCUMENT
  my $document;
  eval {
    $document = $xmlParser->parse_file($documentFilename);
  };
  if ($@) {
    return error($r,'Error parsing XML document',$@);
  }

  ### PARSE STYLESHEET DOCUMENT
  my $stylesheetDocument;
  eval {
    $stylesheetDocument = $xmlParser->parse_file($stylesheetFilename);
  };
  if ($@) {
    return error($r,'Error parsing XSL stylesheet document (XML)',$@);
  }

  ### PARSE STYLESHEET
  my $stylesheet;
  eval {
    $stylesheet = $xsltParser->parse_stylesheet($stylesheetDocument);
  };
  if ($@) {
    return error($r,'Error parsing XSL stylesheet (XSLT)',$@);
  }

  ### TRANSFORM
  my $results;
  eval {
    $results = $stylesheet->transform($document);   ### <--- ERROR HERE
  };
  if ($@) {
    return error($r,'Error transforming document',$@);
  }

  ### PRINT
  eval {
    print $stylesheet->output_string($results);
  };
  if ($@) {
    return error($r,'Error serializing transformed document',$@);
  }

  my $tid = APR::OS::thread_current();
  $r->log_error("[xslTransformer] OK
[tid=$tid|reqno=$statRequestCount|errno=$statErrorCount]");

  return Apache::OK;
}

sub error {
  my ($r,$title,$msg) = @_;

  $statErrorCount++;

  my $tid = APR::OS::thread_current();
  $r->log_error("[xslTransformer] $title - $msg
[tid=$tid|reqno=$statRequestCount|errno=$statErrorCount]");
  return 500;
}

1;


--- The exact error log entry is: ---

[Tue Feb 25 16:04:04 2003] [error] [xslTransformer] Error transforming
document - Can't coerce GLOB to string in entersub at
E:/data/www/perlLib/MyApache/XSLTransformer.pm line 74.
[tid=APR::OS::Thread=SCALAR(0x1205be4)|reqno=1|errno=1]




Thanks,
-Kurt.
__________
kurt george gjerde <ku...@intermedia.uib.no>
intermedia uib, university of bergen

Working for bandwidth.


Re: Help: Can't coerce GLOB to string...

Posted by Kurt George Gjerde <ku...@intermedia.uib.no>.
Ah, an old message of mine. I think this in the end boiled down to 
mod_perl writing this particular error to the server's main error_log 
and not to the actual virtual server's error_log where other errors go.

This might have been fixed. I still run the same build of mp2 (because 
it works) but I guess I should upgrade :)


Thanks,
-Kurt.

Stas Bekman wrote:

> [Forwarded from "jp.guillemin@free.fr" <jp...@free.fr>]
> 
> Hello,
> 
> In response to :
> 
> Kurt George Gjerde wrote:
>  > BTW: I've fixed my "can't coerce GLOB to string" problem I had last
> week.
>  > Was unrelated to mod_perl (sorry). It seems XML::LibXSLT produced some
>  > errors which went straight to STDERR. Under CGI these ends up in the
>  > error_log but under mod_perl it seems STDERR is just a black hole (?).
>  > Would it be possible to map STDERR to log_error()?
> 
> Unless I'm missing something, mod_perl doesn't do anything special with
> STDERR
> (it does tie STDIN and STDOUT for 'perl-script' handlers). Apache opens
> stderr
> to error_log, and then everything just works. e.g. if you do:
> 
> warn "Foo";
> or
> print STDERR "OOOPS\n";
> 
> this ends up in error_log, no?
> 
> I suppose that XML::LibXSLT redefines STDERR then. Try to see what it
> does to
> create this problem.
> 
> 
> 
> The key to this problem is that the function $parser->parse_string()
> cannot take a scalar as argument.
> 
> This way it works and doesn't produce "Can't coerce ..." anymore :
> 
> my $sheet = $parser->parse_string(<<'EOT');
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:output method="text" indent="no"/>
> <xsl:strip-space elements="FILTER_RULE NAT_RULE LOG_RULE"/>
> <!-- this XSLT sheet transforms a netfilter XML rule document into an
> iptables script -->
> 
> <xsl:template match="NETFILTER">
> 
> ...
> 
> EOT
> 
> Best regards
> 
> Jean Philippe GUILLEMIN
> http://shweps.free.fr
> jp.guillemin@free.fr
> 
> 


Re: Help: Can't coerce GLOB to string...

Posted by Stas Bekman <st...@stason.org>.
[Forwarded from "jp.guillemin@free.fr" <jp...@free.fr>]

Hello,

In response to :

Kurt George Gjerde wrote:
 > BTW: I've fixed my "can't coerce GLOB to string" problem I had last
week.
 > Was unrelated to mod_perl (sorry). It seems XML::LibXSLT produced some
 > errors which went straight to STDERR. Under CGI these ends up in the
 > error_log but under mod_perl it seems STDERR is just a black hole (?).
 > Would it be possible to map STDERR to log_error()?

Unless I'm missing something, mod_perl doesn't do anything special with
STDERR
(it does tie STDIN and STDOUT for 'perl-script' handlers). Apache opens
stderr
to error_log, and then everything just works. e.g. if you do:

warn "Foo";
or
print STDERR "OOOPS\n";

this ends up in error_log, no?

I suppose that XML::LibXSLT redefines STDERR then. Try to see what it
does to
create this problem.



The key to this problem is that the function $parser->parse_string()
cannot take a scalar as argument.

This way it works and doesn't produce "Can't coerce ..." anymore :

my $sheet = $parser->parse_string(<<'EOT');
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text" indent="no"/>
<xsl:strip-space elements="FILTER_RULE NAT_RULE LOG_RULE"/>
<!-- this XSLT sheet transforms a netfilter XML rule document into an
iptables script -->

<xsl:template match="NETFILTER">

...

EOT

Best regards

Jean Philippe GUILLEMIN
http://shweps.free.fr
jp.guillemin@free.fr



Re: Help: Can't coerce GLOB to string...

Posted by Stas Bekman <st...@stason.org>.
Kurt George Gjerde wrote:
> On Wed, 26 Feb 2003, Stas Bekman wrote:
> 
>>>use threads;
>>>use threads::shared;
>>
>>why do you need to load threads? Do you plan to spawn your own threads?
> 
> 
> No, they're not supposed to be there.
> 
> 
>>>  ### TRANSFORM
>>>  my $results;
>>>  eval {
>>>    $results = $stylesheet->transform($document);   ### <--- ERROR HERE
>>
>>It's expecting a scalar as an argument, right? could it be that $document is
>>not a scalar? try to print ref($document)?
> 
> 
> It's expecting an XML::LibXML::Document which is a blessed scalar, yes.
> And that's what it gets. I've also done some further tests now and all
> objects ($document, $stylesheet, etc) are identical for ok'ed and failed
> requests. Also, I've found that not all threads fail on the first request
> (but most do) and, older requests may fail as well...

Then you should probably try to interactively debug it.

> I've also tried adding the following to httpd.conf:
> 
>     PerlInterpMaxRequests 10
>     PerlInterpStart 1
> 
>     PerlInterpMax 1
> 
> This would limit the number of threads to 1, right? Well, it doesn't.
> Multiple threads are still being created. I'll post this to the dev list.

No, this is how you control the perl interpreters pool. Threads are controlled by:

<IfModule worker.c>
StartServers         2
MaxClients         150
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>


> There isn't a bugzilla or something for the mp2, is there?

No, most bugs are solved as soon as they come in, at least we are trying to 
and didn't have a need for the bug tracking systems so far.

-- 


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Browser doesn't stop loading a page

Posted by Chris Winters <ch...@cwinters.com>.
Martin Moss wrote:
> Not much to go on I know, but has anybody ever had this problem?
> When I load one of my webpages the browser never stops loading, e.g. the
> page loads ok and I can see and interact with it, but the ie spinning globe
> still keeps spinning and the status bar at the bottom of the page still
> shows the page is loading something..
> 
> The process does seem to run and exit normally in my logs. I'm at a loss as
> to what is causing it. This only happens on one specific page on my server.
> Any ideas would be appreciated.

IME this means you have an external resource (e.g., image, script, 
etc.) in the page that's not being loaded because the site is 
inaccessible or it's overloaded. Generally nothing to do with 
mod_perl :-)

Chris

-- 
Chris Winters (chris@cwinters.com)
Building enterprise-capable snack solutions since 1988.


Browser doesn't stop loading a page

Posted by Martin Moss <Ma...@btinternet.com>.
All,

Not much to go on I know, but has anybody ever had this problem?
When I load one of my webpages the browser never stops loading, e.g. the
page loads ok and I can see and interact with it, but the ie spinning globe
still keeps spinning and the status bar at the bottom of the page still
shows the page is loading something..

The process does seem to run and exit normally in my logs. I'm at a loss as
to what is causing it. This only happens on one specific page on my server.
Any ideas would be appreciated.

Regards

Marty


Re: Help: Can't coerce GLOB to string...

Posted by Kurt George Gjerde <ku...@intermedia.uib.no>.
On Wed, 26 Feb 2003, Stas Bekman wrote:
> > use threads;
> > use threads::shared;
>
> why do you need to load threads? Do you plan to spawn your own threads?

No, they're not supposed to be there.

> >   ### TRANSFORM
> >   my $results;
> >   eval {
> >     $results = $stylesheet->transform($document);   ### <--- ERROR HERE
>
> It's expecting a scalar as an argument, right? could it be that $document is
> not a scalar? try to print ref($document)?

It's expecting an XML::LibXML::Document which is a blessed scalar, yes.
And that's what it gets. I've also done some further tests now and all
objects ($document, $stylesheet, etc) are identical for ok'ed and failed
requests. Also, I've found that not all threads fail on the first request
(but most do) and, older requests may fail as well...

I've also tried adding the following to httpd.conf:

    PerlInterpMaxRequests 10
    PerlInterpStart 1

    PerlInterpMax 1

This would limit the number of threads to 1, right? Well, it doesn't.
Multiple threads are still being created. I'll post this to the dev list.

There isn't a bugzilla or something for the mp2, is there?


thanks,
-Kurt.
__________
kurt george gjerde <ku...@intermedia.uib.no>
intermedia uib, university of bergen

Will work for money.


Re: Help: Can't coerce GLOB to string...

Posted by Stas Bekman <st...@stason.org>.
Kurt George Gjerde wrote:
> Hi,
> 
> I get a "Can't coerce GLOB to string"-error for every new thread that is
> started (mp2). I have no idea why this happens (or even what this error
> actually means).
> 
> The module is included below (line producing the error is marked "ERROR
> HERE"). Error happens for every new thread (on the first request).
> When running ApacheBench  ab -c 3 -n 100 http://...  I get 3 errors and 97
> OKs.

[...]

> use threads;
> use threads::shared;

why do you need to load threads? Do you plan to spawn your own threads?

[...]

>   ### PARSE DOCUMENT
>   my $document;
>   eval {
>     $document = $xmlParser->parse_file($documentFilename);
>   };
>   if ($@) {
>     return error($r,'Error parsing XML document',$@);
>   }
[...]
>   ### TRANSFORM
>   my $results;
>   eval {
>     $results = $stylesheet->transform($document);   ### <--- ERROR HERE

It's expecting a scalar as an argument, right? could it be that $document is 
not a scalar? try to print ref($document)?

[...]
> [Tue Feb 25 16:04:04 2003] [error] [xslTransformer] Error transforming
> document - Can't coerce GLOB to string in entersub at
> E:/data/www/perlLib/MyApache/XSLTransformer.pm line 74.
> [tid=APR::OS::Thread=SCALAR(0x1205be4)|reqno=1|errno=1]


-- 


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com