Revision: 15637
Author: [email protected]
Date: Mon Dec 6 03:29:32 2010
Log: Update Issue 2130
Committing a fix to avoid memory leak of the Client transaction when there
is an error sending the request out.
We take 2 approaches, throwing an IllegalStateException before creating the
client transaction if the dialog is in TERMINATED state (thus avoid
consuming resources for nothing) and in case a race condition occurs
between sending the BYE and the INFO, we terminate the client transaction
if the request couldn't be sent out so that it doesn't leak.
http://code.google.com/p/mobicents/source/detail?r=15637
Modified:
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletRequestImpl.java
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletRequestImpl.java
Thu Dec 2 08:11:40 2010
+++
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletRequestImpl.java
Mon Dec 6 03:29:32 2010
@@ -59,6 +59,7 @@
import javax.sip.ClientTransaction;
import javax.sip.Dialog;
import javax.sip.DialogState;
+import javax.sip.ObjectInUseException;
import javax.sip.ServerTransaction;
import javax.sip.SipException;
import javax.sip.SipProvider;
@@ -1135,6 +1136,12 @@
sipConnector.isUseStaticAddress()) {
optimizeRouteHeaderAddressForInternalRoutingrequest(sipConnector,
request, session, sipFactoryImpl, transport);
}
+
+ if(getDialog() != null && getDialog().getState() != null &&
getDialog().getState().equals(DialogState.TERMINATED)) {
+ // Issue 2130
(http://code.google.com/p/mobicents/issues/detail?id=2130) : Memory leak in
Sip stack when INFO message is used
+ // fail before the ctx is created to
avoid mem leaks
+ throw new IllegalStateException("Error sending request " + request
+ " dialog " + dialog.getDialogId() + " already in TERMINATED state");
+ }
final ClientTransaction ctx =
sipProvider.getNewClientTransaction(request);
ctx.setRetransmitTimer(sipFactoryImpl.getSipApplicationDispatcher().getBaseTimerInterval());
@@ -1321,6 +1328,19 @@
}
} catch (Exception ex) {
throw new IllegalStateException("Error sending request
" + request,ex);
+ } finally {
+ // Issue 2130
(http://code.google.com/p/mobicents/issues/detail?id=2130) : Memory leak in
Sip stack when INFO message is used
+ // fail before the ctx is created to avoid mem leaks
+ if(getTransaction() != null) {
+ if(logger.isDebugEnabled()) {
+ logger.debug("terminating client transaction " +
getTransaction().getBranchId() + " since the request couldn't be sent " +
request);
+ }
+ try {
+ getTransaction().terminate();
+ } catch (ObjectInUseException e) {
+ logger.error("Couldn't terminate the client transaction " +
getTransaction().getBranchId());
+ }
+ }
}
}