[jira] Commented: (SOAP-170) Socket is not closed after apache.axis SOAP call and resulted in too many CLOSE_WAIT state

Vincent OostindiĆ« (JIRA) <[email protected]> Wed, 18 Oct 2006 03:49:35 -0700 (PDT)
Newsgroups gmane.text.xml.soap.devel
Message-ID <12757758.1161168575570.JavaMail.jira@brutus>
    [ http://issues.apache.org/jira/browse/SOAP-170?page=3Dcomments#action_=
12443223 ]=20
           =20
Vincent Oostindi=C3=AB commented on SOAP-170:
----------------------------------------

I can confirm this issue. We have a web application that also acts as a cli=
ent for a remote Web Service. The client was generated automatically, and u=
ses Axis.

Every call to the remote service adds a new socket with state CLOSE_WAIT. I=
t's just a matter of time before there are no longer any sockets available.

I've been able to reproduce the problem with Axis 1.3 and Axis 1.4.

The code from Jiping Yao resolves it. We've patched Axis 1.3, and now the p=
roblem doesn't occur anymore.

> Socket is not closed after apache.axis SOAP call and resulted in too many=
 CLOSE_WAIT state
> -------------------------------------------------------------------------=
-----------------
>
>                 Key: SOAP-170
>                 URL: http://issues.apache.org/jira/browse/SOAP-170
>             Project: SOAP
>          Issue Type: Bug
>         Environment: Both Windows and UNIX
>            Reporter: Jiping Yao
>            Priority: Critical
>
> I am not be able to send email to [email protected] so I opend it as=
 bug regport.
> Currently, I ran into the problem with every socket not closed as shown b=
y numerous SOCKET_WAIT state after making SOAP call with apache.axis and th=
ose states are stayed there forever.  Once we reach to the maximum number f=
or SOCKET_WAIT state (operating system could not allocate any more connecti=
ons as indicated by Too many open files), we could not make any SOAP call u=
ntil we restart JVM.
> Here is the original code where "currentMessage =3D currMsg;" could cuase=
s the sokcet leaking (see JYao's comment)
> public class SOAPPart extends javax.xml.soap.SOAPPart implements Part
> {
> =09.
> =09.
> =09.
>     private void setCurrentForm(Object currMsg, int form) {
>         if (log.isDebugEnabled()) {
>             String msgStr;
>             if (currMsg instanceof String) {
>                 msgStr =3D (String)currMsg;
>             } else {
>                 msgStr =3D currMsg.getClass().getName();
>             }
>             log.debug(Messages.getMessage("setMsgForm", formNames[form],
>                     "" + msgStr));
>         }
>         // only change form if allowed
>         if (isFormOptimizationAllowed()) {
>             currentMessage =3D currMsg;   // JYao's comment: socket is le=
aking here if currentMessage was an instance of SocketInputStream.
>             currentForm =3D form;
>             if (currentForm =3D=3D FORM_SOAPENVELOPE) {
>                     currentMessageAsEnvelope =3D (org.apache.axis.message=
.SOAPEnvelope) currMsg;
>             }
>         }
>     }
> The following is what I changed for the same function within the block be=
tween of begin and end. After deployed recompiled code, all sockets allocat=
ed for apache.axix SOAP call are properly closed and the CLOSE_WAIT state a=
ssociated with SOAP call is no longer seen by netstat -n in windows.
> public class SOAPPart extends javax.xml.soap.SOAPPart implements Part
> {
> =09.
> =09.
> =09.
>     private void setCurrentForm(Object currMsg, int form) {
>         if (log.isDebugEnabled()) {
>             String msgStr;
>             if (currMsg instanceof String) {
>                 msgStr =3D (String)currMsg;
>             } else {
>                 msgStr =3D currMsg.getClass().getName();
>             }
>             log.debug(Messages.getMessage("setMsgForm", formNames[form],
>                     "" + msgStr));
>         }
>         // only change form if allowed
>         if (isFormOptimizationAllowed()) {
>           =20
> =09// begin of JYao's change:=20
> =09
> =09// currentMessage should be closed if it is an instance of SocketInput=
Stream
>             // before to take any new instance of whatever SOAP message, =
otherwise the socket might be leaked
>             if (currentMessage instanceof SocketInputStream)
>             {
>                 SocketInputStream socketInput =3D (SocketInputStream) cur=
rentMessage;
>                 try
>                 {
>                     socketInput.close();   // the socket is properly clos=
ed=20
>                 }
>                 catch (IOException e)
>                 {
>                     // never got there
>                 }
>             }=20
> =09// end of JYao's change
>             currentMessage =3D currMsg; // JYao: safely take any other SO=
AP message
>             currentForm =3D form;
>             if (currentForm =3D=3D FORM_SOAPENVELOPE) {
>                     currentMessageAsEnvelope =3D (org.apache.axis.message=
.SOAPEnvelope) currMsg;
>             }
>         }
>     }
>     .=20
>     .
>     .
> }
> I am not sure if this is a bug or intended by authors. If it is not a bug=
, please give us advice how to get those sockets closed after each SOAP cal=
l.
> Thanks,
> Jiping Yao

--=20
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: htt=
p://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira