You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by André Warnier <aw...@ice-sa.com> on 2007/09/20 13:17:15 UTC

re-post : duplicate sockets with mp2, apache2, linux

This is a repost of "duplicate sockets ? mod-perl 2.0.2, apache 2.2", 
because I still don't understand what's happening and can still not find 
the problem.
I would be very grateful if anyone could help me, because I'm out of my 
wits.

More information is currently accessible at
http://ska.dev.wissensbank.com/mod_perl_list/
which provides a link to the module code, access to the logfiles 
involved etc..

Summary :

I wrote a custom PerlAuthenHandler called AM::Authtest.pm.
This handler, at some stage, open a TCP connection to an external 
database server module, sends a message on that connection, reads the 
module's answer on the same connection, and closes the connection.  The 
answer is supposed to indicate if the authentication succeeds.
By and large, according to its logfile, the module seems to be doing 
what it should, in the order it should do it.
The problem is that, although in the PerlAuthHandler (to my knowledge 
and according to the logfile), the TCP connection in the handler is 
opened only once, the external server module seems to see *two* separate 
connections being opened almost simultaneously.  Subsequently what 
*seems* to happen is that the PerlAuthHandler sends the message on one 
of these connections, but tries to read the answer from the other, and 
gets stuck waiting for something that never comes.
I say *seems*, because that's what I guess from the various logfiles, 
although I must say I'm really in the dark here.

Question 1 : has anyone seen this kind of problem before ?

Question 2 : the external server with whom I communicate is a piece of 
code outside my control, and what it logs is a bit limited.
I would gladly try to provide a simplified example of what is happening, 
but for that I would need another TCP server module, to which I could 
open a connection, send something and read a response.  It would have to 
be something that leaves a clear trace of wether one or two connections 
are taking place. (I could use the "echo" port, but that leaves no 
separate trace for instance).
Anyone think of something ?

Thank you in advance.


P.S.
Some data already established by earlier attempts :
- the PerlAuthenHandler module is not pre-loaded at Apache server 
start/restart
- according to the Apache logfiles, the handler is called only once, 
when it should (well, twice in fact but the first time is just returns a 
401 response and does not open a TCP connection)
- opening the TCP connection via IO::Socket::INET, or socket() makes no 
difference, there are always 2 connections instead of one
- reading/writing to the connection via read,sysread,syswrite,send/recv, 
etc.. make no difference
- using a perl "handle" such as SRV or a lexical like "my $SRV" for the 
handle makes no difference
- the same server on which all this is taking place has lots of perl and 
Apache stuff running on it, also with client/server socket stuff, and 
everything else seems to run fine
- I am not perl-guru level, but no beginner either. I have written perl 
TCP client/server applications before, and other Apache2 modules.  But 
this case really has me stumped.




Re: re-post : duplicate sockets with mp2, apache2, linux

Posted by André Warnier <aw...@ice-sa.com>.
-- solved --

My thanks, but also my deepest apologies to anyone who bothered spending 
time considering this post and its predecessor.

There is no voodoo and no problem with duplicate sockets or connections, 
at least not in Apache2 or mod_perl2.  The problem was not in the code 
of my PerlAuthenHandler module either, it was with my setup (and thus 
with me anyway).

For the curious, I was connecting to an external database module, which 
itself connects to a database system.  The problem was that instead of 
telling the external module to connect to the database system, I was 
telling it to connect to itself.  Which caused it to receive ipso-facto 
a second connection request (and log this event), which caused me to 
believe that it was the perl module which was connecting twice.
A classic case of re-reading something 20 times and overlooking the obvious.

AW


Re: re-post : duplicate sockets with mp2, apache2, linux

Posted by Perrin Harkins <pe...@elem.com>.
On 9/21/07, André Warnier <aw...@ice-sa.com> wrote:
> This is an Apache2 PerlAuthenHandler.  How do I run that under
> the debugger ?

http://www.perl.com/pub/a/2006/02/09/debug_mod_perl.html
And if you haven't read it before:
http://modperlbook.org/html/part4.html

> (I am not at all familiar with the debugger per se, so
> if this is a big setup, it might be more efficient to go another route.)

Okay, but it's hard to beat the debugger when you don't know what's happening.

>  From the logfile of the database module (the external server to which I
> connect from the handler), I do see when the two sockets appear though :
> at the same second or within 1 second of one another.

A few thousand things probably happen in that second.

> I mean, purely in the abstract, is there any circumstance in which a
> single execution of an IO::Socket::INET->new() or a "socket() +
> connect()" could possibly open 2 connections to the same destination ?

None that I know.

> Or else : does anyone know of another simple-to-set-up mod_perl/Apache2
> module that opens a connection to an external server, and which I could
> run to see if it does the same kind of thing ?

DBI.  Or LWP.  Or one of the mail modules.

- Perrin

Re: re-post : duplicate sockets with mp2, apache2, linux

Posted by André Warnier <aw...@ice-sa.com>.
Perrin Harkins wrote:
[...]
> Also, have you tried running your code in the debugger to try to see
> when the second socket appears?
> 
Hee, no.  This is an Apache2 PerlAuthenHandler.  How do I run that under 
the debugger ?  (I am not at all familiar with the debugger per se, so 
if this is a big setup, it might be more efficient to go another route.)

 From the logfile of the database module (the external server to which I 
connect from the handler), I do see when the two sockets appear though : 
at the same second or within 1 second of one another.  I can also see 
that one of these sockets indeed receives what the handler sends it as a 
request, while the other one receives nothing.

Now, assuming for a moment that indeed the handler opens the connection 
only once (what I see in the Apache logfile), and that the external 
target server sees two connections being opened (what I see in its 
logfile); and assuming that the handler itself is called only once at 
the proper time (what I also see in the Apache logfile), then what 
conceivable explanation could there be ?
I mean, purely in the abstract, is there any circumstance in which a 
single execution of an IO::Socket::INET->new() or a "socket() + 
connect()" could possibly open 2 connections to the same destination ?

Or else : does anyone know of another simple-to-set-up mod_perl/Apache2 
module that opens a connection to an external server, and which I could 
run to see if it does the same kind of thing ?


Re: re-post : duplicate sockets with mp2, apache2, linux

Posted by Perrin Harkins <pe...@elem.com>.
On 9/20/07, André Warnier <aw...@ice-sa.com> wrote:
> Question 2 : the external server with whom I communicate is a piece of
> code outside my control, and what it logs is a bit limited.
> I would gladly try to provide a simplified example of what is happening,
> but for that I would need another TCP server module, to which I could
> open a connection, send something and read a response.  It would have to
> be something that leaves a clear trace of wether one or two connections
> are taking place. (I could use the "echo" port, but that leaves no
> separate trace for instance).
> Anyone think of something ?

There are lots of simple TCP servers on CPAN.  Or you could just start
an apache server and make an HTTP request over a socket.

Also, have you tried running your code in the debugger to try to see
when the second socket appears?

- Perrin