Uploaded image for project: 'Synapse'
  1. Synapse
  2. SYNAPSE-1003

Memory Leaks while using Anonymous Endpoints

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Blocker
    • Resolution: Fixed
    • 2.0, 2.1
    • 3.0.0
    • Core
    • Patch

    Description

      When using dynamic Load Balance endpoints in a send mediator and the endpoints have no name in the xml configuration, they get given a unique name from the EndpointFactory.

      • Every endpoint is registered over this name and an EndpointView as MBean is created. AdressEndpoints in a LoadbalanceEndpoint never gets deregistered, causing a memory leak.
      • Every EndpointView registers a statistic runnable in a ScheduledExecutorService, but if the endpoint gets destroyed, the runnable never gets canceled, causing another memory leak.

      The first issue is reproducible by loading the following sequence:

      <sequence xmlns="http://ws.apache.org/ns/synapse" name="main">
      	<in>
      		<send>
      			<endpoint>
      				<loadbalance>
      					<endpoint>
      						<loadbalance>
      							<endpoint>
      								<address uri="http://localhost:8280/ServiceResponseDummy1"/>
      							</endpoint>
      														<endpoint>
      								<address uri="http://localhost:8280/ServiceResponseDummy2"/>
      							</endpoint>
      
      						</loadbalance>
      					</endpoint>
      					<endpoint>
      						<loadbalance>
      							<endpoint>
      								<address uri="http://localhost:8280/ServiceResponseDummy3"/>
      							</endpoint>
      														<endpoint>
      								<address uri="http://localhost:8280/ServiceResponseDummy4"/>
      							</endpoint>
      
      						</loadbalance>
      					</endpoint>
      				</loadbalance>
      			</endpoint>
      		</send>
      	</in>
      	<out>
      		<log level="custom">
      			<property name="simple out sequence: " expression="get-property('From')"/>
      		</log>
      		<send/>
      	</out>
      </sequence>
      

      The second is reproducible by dynamically loading sequence and engaging it (a case we've seen where some people prefer to do this over statically configuring when they have over 1000's of services to manage):

      public class TestCase extends AbstractMediator implements ManagedLifecycle {
      	private static final Log log = LogFactory.getLog(ServiceConfigurationMediator.class);
      
      	public boolean mediate(MessageContext messageContext) {
      		try {
      			InputStream in = getClass().getResourceAsStream("/test/sequence.xml");
      
      			XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(in);
      			StAXOMBuilder builder = new StAXOMBuilder(reader);
      			OMElement xmlSequence = builder.getDocument().getOMDocumentElement();
      
      			SequenceMediator mediatorInstance = new SequenceMediatorFactory().createAnonymousSequence(xmlSequence, null);
      			if (mediatorInstance instanceof ManagedLifecycle)
      				((ManagedLifecycle) mediatorInstance).init(messageContext.getEnvironment());
      			boolean result = mediatorInstance.mediate(messageContext);
      			if (mediatorInstance instanceof ManagedLifecycle)
      				((ManagedLifecycle) mediatorInstance).destroy();
      
      			return result;
      		} catch (Throwable e) {
      			log.error("Fail: " + e, e);
      			throw new SynapseException(e.getMessage(), e);
      		}
      
      	}
      
      }
      

      I would like to contribute the attached diff that addresses the above issues for your consideration (it has been created over 2.1 branch).

      Attachments

        1. memory-leak.diff
          2 kB
          Ravi Undupitiya

        Activity

          People

            hiranya Hiranya Kasub Jayathilaka
            raviu Ravi Undupitiya
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: