axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yao, Jiping" <J...@talk.com>
Subject TOO MANY OPEN FILES SHOWN BY CLOSE_WAIT IN BOTH WINDDOWS AND UNIX
Date Mon, 21 Aug 2006 19:51:50 GMT
Hi folks,	
	First I have to say you guys did a great job. 
	Currently, we ran into the problem with every socket not closed as
shown by numerous SOCKET_WAIT state after making SOAP call with apache.axis
and those states are stayed there forever.  Once we reach to the maximum
number for SOCKET_WAIT state (operating system could not allocate any more
connections as indicated by Too many open files), we could not make any SOAP
call until we restart JVM.

I tried searching solution from internet for how to explicitly close those
sockets allocated for apache.axis SOAP call but I could not get any useful
help. I eventually downloaded the source code of apache.axis and recompiled
on my local box for debugging. I found out where potential socket leak is
located.

Here is the original code where the red line may cause potential socket
leaking (see JYao's comment)

public class SOAPPart extends javax.xml.soap.SOAPPart implements Part
{
	.
	.
	.
    private void setCurrentForm(Object currMsg, int form) {
        if (log.isDebugEnabled()) {
            String msgStr;
            if (currMsg instanceof String) {
                msgStr = (String)currMsg;
            } else {
                msgStr = currMsg.getClass().getName();
            }
            log.debug(Messages.getMessage("setMsgForm", formNames[form],
                    "" + msgStr));
        }

        // only change form if allowed
        if (isFormOptimizationAllowed()) {
            currentMessage = currMsg;   // JYao's comment: socket is leaking
here if currentMessage was an instance of SocketInputStream.
            currentForm = form;
            if (currentForm == FORM_SOAPENVELOPE) {
                    currentMessageAsEnvelope =
(org.apache.axis.message.SOAPEnvelope) currMsg;
            }
        }
    }


The following is what I changed for the same function with bold lines of
green. After deployed recompiled code, all sockets allocated for apache.axix
SOAP call are properly closed and the CLOSE_WAIT state associated with SOAP
call is no longer seen by netstat -n in windows.

public class SOAPPart extends javax.xml.soap.SOAPPart implements Part
{
	.
	.
	.

    private void setCurrentForm(Object currMsg, int form) {
        if (log.isDebugEnabled()) {
            String msgStr;
            if (currMsg instanceof String) {
                msgStr = (String)currMsg;
            } else {
                msgStr = currMsg.getClass().getName();
            }
            log.debug(Messages.getMessage("setMsgForm", formNames[form],
                    "" + msgStr));
        }

        // only change form if allowed
        if (isFormOptimizationAllowed()) {

           
	// begin of JYao's change: 
	
	// currentMessage should be closed if it is an instance of
SocketInputStream
            // before to take any new instance of whatever SOAP message,
otherwise the socket might be leaked
            if (currentMessage instanceof SocketInputStream)
            {
                SocketInputStream socketInput = (SocketInputStream)
currentMessage;
                try
                {
                    socketInput.close();   // the socket is properly closed 
                }
                catch (IOException e)
                {
                    // never got there
                }
            } 

	// end of JYao's change

            currentMessage = currMsg; // JYao: safely take any other SOAP
message
            currentForm = form;
            if (currentForm == FORM_SOAPENVELOPE) {
                    currentMessageAsEnvelope =
(org.apache.axis.message.SOAPEnvelope) currMsg;
            }
        }
    }
    . 
    .
    .
}

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 call.

Thanks,
Jiping Yao
Talk America

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org


Mime
View raw message