You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by ubr <ul...@senstadt.verwalt-berlin.de> on 2000/06/28 16:35:29 UTC

mod_perl socket problem

Hello mailinglist, i have a problem...

I wrote a mod_perl-script running on an Apache-Server which has 
to receive a GIF-File from a NT-Server via a IO::Socket. (see code below)
On the NT-side there is a JAVA-programm. 

Here some information about the used software:
(A) my workstation:
   Linux 2.2.13
   Apache/1.3.9 (Unix)  (SuSE/Linux) PHP/3.0.12 mod_perl/1.21
   perl, version 5.005_03
(B) production server:
   Linux 2.2.7
   Apache/1.3.6 (Unix)  (SuSE/Linux) PHP/3.0.7 mod_perl/1.19
   perl, version 5.005_02
(C) test-server:
   Linux 2.2.5
   Apache/1.3.4 (Unix)  (SuSE/Linux) PHP/3.0.7 mod_perl/1.18
   perl, version 5.005_02

I developed and tested the script on my workstation (A) and it worked.
Moving to the production server (B)  or another test-server (C)  the 
mod_perl-script  seems to crash without a sigh (C) or doesn´t receive 
the whole file (B).

I have concentrated on the more severe problem (crashing on test-server C). 

The script cycles through the while-loop receiving a packet, sends 
a newline to the JAVA-program and writes to the IMG-Handle.
And then after some packets it dies, just before the handshaking newline.

The debugging output "GetFile: ready" does´nt appear in the logfile (GISLOG)
and the function does´nt return to the main program (No further output 
in GISLOG)

There is no message in the apache error_log and also 
standalone Perl in debugmode (perl -d ) gave up without any comment,
leaves me alone on the commandline.

And more confusing is:
The httpd child process does not die, according to the server status report. 
Why dies perl in debug-mode when mod_perl survives it. At least i think so, 
because as far as my knowledge goes mod_perl is a part of the httpd-process.

I would appreciate hints for further reading and/or tips how to debug this 
problem. 
The apache and linux versions are different on the three servers, 
suggesting me to update. But i hope there is another solution for this problem.

Can someone point me in the right direction?

Many thanks in advance

Uli




part of geoServ.pl -------------------------------------------------------------

1    sub GetFile {
2	my ($remote_host, $filename,$remote_port)=@_;
3	my $i;
4	$i=0;
5	open(IMG,"> $htmlroot/$filename");
6        print $GISLOG "GetFile: trying  $remote_host:$remote_port :\n";
7	$socket = IO::Socket::INET->new(PeerAddr => $remote_host,
8					PeerPort => $remote_port,
9					Proto    => "tcp",
10					Timeout => 5,
11					Type     => SOCK_STREAM)
12	    or die "Couldnt connect to $remote_host:$remote_port : $@\n";
13	print $GISLOG "GetFile: connected $remote_host:$remote_port :\n";
14	$socket->autoflush(1);
15	if ($socket){ print "Connected<br>\n";}
16	$fSize= <$socket>;
17	print "fSize: $fSize XXX<br>\n";
18	print $socket "\n";
19	print $GISLOG "GetFile: receiving ";
20	print  "GetFile: receiving .... ";
21	$sizeRead=0;
22	while(<$socket>){
23	    print $GISLOG $i++." ";
24	    print $socket "\n"; # ok, there on the other side
25	    print IMG $_;
26	}
27	print $GISLOG "GetFile: ready ";
28	close($socket);
29	close(IMG);
30    }

-----------------------------------------------------------------------------



PS: The problem appears while redeveloping parts of a project 
for the Digital Environmental Atlas of Berlin. 
If You are interested, an entrypoint to see the older, working solution is for example:

 http://www.sensut.berlin.de/sensut/umwelt/uisonline/dua96/html/ek102.ht

Re: mod_perl socket problem

Posted by Rob Tanner <rt...@onlinemac.com>.

--On Wednesday, June 28, 2000 4:35 PM +0200 ubr 
<ul...@senstadt.verwalt-berlin.de> wrote:

> Hello mailinglist, i have a problem...
>
> I wrote a mod_perl-script running on an Apache-Server which has
> to receive a GIF-File from a NT-Server via a IO::Socket. (see code below)
> On the NT-side there is a JAVA-programm.
>
> Here some information about the used software:
> (A) my workstation:
>    Linux 2.2.13
>    Apache/1.3.9 (Unix)  (SuSE/Linux) PHP/3.0.12 mod_perl/1.21
>    perl, version 5.005_03
> (B) production server:
>    Linux 2.2.7
>    Apache/1.3.6 (Unix)  (SuSE/Linux) PHP/3.0.7 mod_perl/1.19
>    perl, version 5.005_02
> (C) test-server:
>    Linux 2.2.5
>    Apache/1.3.4 (Unix)  (SuSE/Linux) PHP/3.0.7 mod_perl/1.18
>    perl, version 5.005_02
>
> I developed and tested the script on my workstation (A) and it worked.
> Moving to the production server (B)  or another test-server (C)  the
> mod_perl-script  seems to crash without a sigh (C) or doesn´t receive
> the whole file (B).
>

I'm not all that familiar with the various issues surrounding the earlier 
releases of mod_perl, but you do notice the above trend.  Earlier versions 
of mod_perl and Apache have the problem, the later do not.  Mod_perl's 
current release is 1.24 and apache is 1.3.12.  Unless there's a 
show-stopper bug in the most recent version of something, I like to keep up 
to date so that I don't rediscover something that has already been fixed.

> I have concentrated on the more severe problem (crashing on test-server
> C).
>
> The script cycles through the while-loop receiving a packet, sends
> a newline to the JAVA-program and writes to the IMG-Handle.
> And then after some packets it dies, just before the handshaking newline.
>
> The debugging output "GetFile: ready" does´nt appear in the logfile
> (GISLOG) and the function does´nt return to the main program (No further
> output  in GISLOG)
>

Looking at your code, one thing I think might be quite problematics is the 
use of the "die" statement.  According to the eagle book, except during 
apache initialization and startup, die does not necessarily behave as 
advertised.  I suggest that instead you print to STDERR since apache 
reopens that handle to point to error_log, and then simply return with an 
SERVER_ERROR set.  That way apache handles it as apache was designed to do, 
and you won't suffer any of the possible negative consequences of "die". 
That might get you a long way towards figuring out what all is going on.

And don't overlook the profuse use of "print STDERR" to write out debugging 
information to the error_log.  That one mechanism has helped me to find 
more bugs than I'm even willing to admit to have had.

Hope that's helpful.

-- Rob


       _ _ _ _           _    _ _ _ _ _
      /\_\_\_\_\        /\_\ /\_\_\_\_\_\
     /\/_/_/_/_/       /\/_/ \/_/_/_/_/_/  QUIDQUID LATINE DICTUM SIT,
    /\/_/__\/_/ __    /\/_/    /\/_/          PROFUNDUM VIDITUR
   /\/_/_/_/_/ /\_\  /\/_/    /\/_/
  /\/_/ \/_/  /\/_/_/\/_/    /\/_/         (Whatever is said in Latin
  \/_/  \/_/  \/_/_/_/_/     \/_/              appears profound)

  Rob Tanner
  McMinnville, Oregon
  rtanner@onlinemac.com