I had the same problem and submitted a patch (with help from Bill
Barker).  The patch is below and I attached the thread Bill and I had to
come to it in case your curious.  You'll have to rebuild the native
connector, but this should solve your problem.  What platform are you
on?  Did you build the native connector yourself?  Or where did you get
the binary from?

Remy or anyone else working on the native connector,
I'm not the only one who has seen this problem and obviously the Java
code isn't doing what you expected.  Any chance you of this patch
getting accepted now?  If not, would you be able to explain why?  Thanks
in advance.
,
Josh.

bash-2.03$ diff -c network.c network.c.orig
*** network.c   Mon Feb  6 12:50:54 2006
--- network.c.orig      Mon Feb  6 12:50:11 2006
***************
*** 385,391 ****
      UNREFERENCED_STDARGS;
      TCN_ASSERT(sock != 0);
      TCN_ASSERT(s->sock != NULL);
+     apr_socket_opt_set( s->sock, APR_SO_REUSEADDR, 1 );
      return (jint)apr_socket_bind(s->sock, a);
  }

> -----Original Message-----
> From: Sean Neeley [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, February 22, 2006 10:06 AM
> To: users@tomcat.apache.org
> Subject: Using APR with tomcat leaves port 8009 bound when 
> tomcat is terminated?
> 
> 
> Hi, 
> 
>  
> 
> I'm using APR 1.2.2 with Tomcat 5.5.15.  Occasionally I need 
> to restart the JVM, and so I have one of my servlets call 
> System.exit(0).  When using the APR libraries with tomcat, 
> exiting the JVM in this manor leaves port 8009 in the 
> FIN_WAIT2 state (see netstat man page).  This prevents me 
> from starting tomcat back up immediately.  I receive an error 
> saying that the tomcat port is already bound.  If I remove 
> the APR libraries so that tomcat does not use them, I no 
> longer encounter this problem.  Can someone help?  I would 
> like to use APR, but this problem prevents me.  I have 
> already posted this issue to the APR mailing list, and they 
> say that the problem is with tomcat. Thanks.
> 
>  
> 
> - Sean
> 
>  
> 
> 
--- Begin Message ---
Here's a patch for the native APR connector so that fixes problems
binding on restart (see attached thread for more details).  Thanks go
out to Bill Barker for coming up with this.  I've tested this on
Windows, Solaris, and AIX and it works fine.  It would be great if this
could be included in the 1.1.2 native connector.  Thanks.
,
Josh.
 
bash-2.03$ diff -c network.c network.c.orig
*** network.c   Mon Feb  6 12:50:54 2006
--- network.c.orig      Mon Feb  6 12:50:11 2006
***************
*** 385,391 ****
      UNREFERENCED_STDARGS;
      TCN_ASSERT(sock != 0);
      TCN_ASSERT(s->sock != NULL);
-     apr_socket_opt_set( s->sock, APR_SO_REUSEADDR, 1 );
      return (jint)apr_socket_bind(s->sock, a);
  }
 
--- 385,390 ----
--- Begin Message ---
I was doing a cut-and paste from the code in Httpd.  In tcnative, 's' is 
it's internal socket structure, and the APR socket is s->sock.

"Fenlason, Josh" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
I added the following line to
tomcat-native.1.1.1/jni/native/src/network.c (added at line 388):
apr_socket_opt_set( s, APR_SO_REUSEADDR, 1 );
But I'm still running into the same problem.

Does anyone who works on the APR Connector have any input on this?  Or
do I need to post this issue on the dev list?  Thanks.
,
Josh.

> -----Original Message-----
> From: news [mailto:[EMAIL PROTECTED] On Behalf Of Bill Barker
> Sent: Monday, January 30, 2006 10:07 PM
> To: users@tomcat.apache.org
> Subject: Re: Re: APR Connector Shutdown Problem
>
>
> Not by me, I don't really work on the APR Connector ;-).
>
> In the bind method in network.c is probably easiest.  If you
> want your patch
> to be accepted by the dev team, then you should probably wrap it in a
> '#ifndef WIN32' like httpd does (don't know why, and care
> even less :).
>
> "Fenlason, Josh" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> Is there no intent to fix this issue?  Where would I need to
> make that patch?  Thanks. , Josh.
>
> > -----Original Message-----
> > From: news [mailto:[EMAIL PROTECTED] On Behalf Of Bill Barker
> > Sent: Friday, January 27, 2006 8:59 PM
> > To: users@tomcat.apache.org
> > Subject: Re: APR Connector Shutdown Problem
> >
> >
> > Yeah, the difference is that Httpd calls:
> >   apr_socket_opt_set(s, APR_SO_REUSEADDR, one);
> > on the Socket before binding it.  That allows it to bind
> even though
> > there are still half-closed sockets on systems like Solaris.
> >
> > About the only work-around is to hack the tcnative code,
> and recompile
> > it.
> >
> > "Fenlason, Josh" <[EMAIL PROTECTED]> wrote in message
> >
> news:[EMAIL PROTECTED]
> > I added the Listener you mentioned to server.xml, but I'm
> still seeing
> > the issue.  The problem is happening when run the
> shutdown.sh.  I can
> > understand if things aren't all clean and tidy if Tomcat
> crashed, but
> > you shouldn't have to wait 4 minutes to restart Tomcat
> after a planned
> > shutdown.  Apache doesn't work like that.  Any other suggestions on
> > how to get this to shutdown properly?  Thanks in advance. , Josh.
> >
> > > -----Original Message-----
> > > From: Mladen Turk [mailto:[EMAIL PROTECTED]
> > > Sent: Friday, January 27, 2006 1:24 AM
> > > To: Tomcat Users List
> > > Subject: Re: APR Connector Shutdown Problem
> > >
> > >
> > > Fenlason, Josh wrote:
> > > > I'm running into a problem with the APR connector not
> > shutting down
> > > > properly.  Tomcat runs fine and there are no errors on
> > > shutdown, but if
> > > > I shut Tomcat down and start it up again I get a socket
> > bind failed
> > > > error in the catalina log (attached).  I have to wait
> for several
> > > > minutes between shutdown and startup for Tomcat to be able
> > > to startup
> > > > correctly.  If I run Tomcat without the APR connector, I
> > > don't have this
> > > > issue.  This does not occur on Windows, but does on
> > Solaris and AIX.
> > > > Has anyone else seen this? One thing I noticed is that
> the first
> > > > thing logged on
> > > shutdown is an
> > > > "AjpAprProtocol pause" entry, but there is no shutdown,
> > > stop or destroy.
> > > > Is there any chance the APR connector is just getting
> > > paused and nothing
> > > > is actually stopping it?
> > > > Any help would be greatly appreciated.  Thanks in advance.
> > >
> > >
> > > I suppose you have:
> > > <Listener
> > className="org.apache.catalina.core.AprLifecycleListener" />
> > > in your server.xml
> > >
> > > But of course it doesn't guarantee it will be executed in
> > all cases,
> > > if the JVM crashes for example. On Solaris it can take up
> > to 4 minutes
> > > until the OS recycles the zombie socket.
> > > You can use:
> > > ndd -set /dev/tcp tcp_time_wait_interval 60000
> > > To lower that value.
> > >
> > > APR does not try to fool the OS like JVM, but rather behaves like
> > > Apache httpd.
> > >
> > > Regards,
> > > Mladen.
> > >
> > >
> > >
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> >
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--- End Message ---

--- End Message ---
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to