NullPointerException during startup of DiscoveryNetworkConnector when using an
HTTP URL for an inactive remote broker.
----------------------------------------------------------------------------------------------------------------------
Key: AMQ-2472
URL: https://issues.apache.org/activemq/browse/AMQ-2472
Project: ActiveMQ
Issue Type: Bug
Components: Connector
Affects Versions: 5.3.0
Environment: ActiveMQ 5.3.0 release (08/10/2009), Windows XP
Reporter: Stirling Chow
Symptom
========
When starting a statically-configured network of two AMQ brokers, each of which
uses HTTP as their transport, if one of the brokers is not running when the
other starts up, the following NPE appears in the logs:
2009-11-01 11:05:53,626 [AlarmPoint Node-main] INFO - - Using Persistence
Adapter: MemoryPersistenceAdapter
2009-11-01 11:05:53,626 [AlarmPoint Node-main] INFO - - ActiveMQ 5.3.0 JMS
Message Broker (localhost) is starting
2009-11-01 11:05:53,626 [AlarmPoint Node-main] INFO - - For help or more
information please see: http://activemq.apache.org/
2009-11-01 11:05:53,829 [AlarmPoint Node-main] WARN - - 2009-11-01
11:05:53.445::INFO: Logging to STDERR via org.mortbay.log.StdErrLog
2009-11-01 11:05:53,876 [AlarmPoint Node-main] WARN - - 2009-11-01
11:05:53.492::INFO: jetty-6.1.9
2009-11-01 11:05:53,922 [AlarmPoint Node-main] WARN - - 2009-11-01
11:05:53.538::INFO: Started socketconnec...@localhost:50000
2009-11-01 11:05:53,922 [AlarmPoint Node-main] INFO - - Connector
http://localhost:50000 Started
2009-11-01 11:05:53,922 [AlarmPoint Node-main] INFO - - Establishing
network connection from vm://localhost to http://192.168.168.44:50001
2009-11-01 11:05:53,938 [AlarmPoint Node-main] DEBUG - - binding to broker:
localhost
2009-11-01 11:05:53,938 [AlarmPoint Node-main] INFO - - Connector
vm://localhost Started
2009-11-01 11:05:57,954 [AlarmPoint Node-main] DEBUG - - Shutting down VM
connectors for broker: localhost
2009-11-01 11:05:57,954 [ActiveMQ Transport Stopper: vm://localhost#0] DEBUG
- - Stopping connection: vm://localhost#0
2009-11-01 11:05:57,954 [ActiveMQ Transport Stopper: vm://localhost#0] DEBUG
- - Stopped transport: vm://localhost#0
2009-11-01 11:05:57,954 [ActiveMQ Transport Stopper: vm://localhost#0] DEBUG
- - Connection Stopped: vm://localhost#0
2009-11-01 11:05:57,954 [AlarmPoint Node-main] INFO - - Connector
vm://localhost Stopped
2009-11-01 11:05:57,954 [AlarmPoint Node-main] ERROR - - Could not stop
service: HTTP Reader http://192.168.168.44:50001. Reason:
java.lang.NullPointerException
java.lang.NullPointerException
at
org.apache.activemq.transport.http.HttpClientTransport.doStop(HttpClientTransport.java:202)
at org.apache.activemq.util.ServiceSupport.stop(ServiceSupport.java:69)
at
org.apache.activemq.transport.TransportFilter.stop(TransportFilter.java:64)
at
org.apache.activemq.transport.TransportFilter.stop(TransportFilter.java:64)
at
org.apache.activemq.transport.ResponseCorrelator.stop(ResponseCorrelator.java:125)
at
org.apache.activemq.util.ServiceSupport.dispose(ServiceSupport.java:43)
at
org.apache.activemq.network.DiscoveryNetworkConnector.onServiceAdd(DiscoveryNetworkConnector.java:134)
at
org.apache.activemq.transport.discovery.simple.SimpleDiscoveryAgent.start(SimpleDiscoveryAgent.java:77)
at
org.apache.activemq.network.DiscoveryNetworkConnector.handleStart(DiscoveryNetworkConnector.java:182)
at
org.apache.activemq.network.NetworkConnector$1.doStart(NetworkConnector.java:56)
at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:53)
at
org.apache.activemq.network.NetworkConnector.start(NetworkConnector.java:199)
at
org.apache.activemq.broker.BrokerService.startAllConnectors(BrokerService.java:1933)
at
org.apache.activemq.broker.BrokerService.start(BrokerService.java:471)
at
com.invoqsystems.foundation.component.communication.MessageBusImpl.startJmsBroker(MessageBusImpl.java:602)
at
com.invoqsystems.foundation.component.communication.MessageBusImpl.start(MessageBusImpl.java:364)
at
com.invoqsystems.apex.component.communication.NodeMessageBusImpl.start(NodeMessageBusImpl.java:207)
at
com.invoqsystems.apex.component.node.manager.NodeManager.startMessagingServer(NodeManager.java:975)
at
com.invoqsystems.apex.component.node.manager.NodeManager.start(NodeManager.java:199)
at
com.invoqsystems.apex.AlarmPointNode.startNodeManager(AlarmPointNode.vaja:162)
at com.invoqsystems.apex.AlarmPointNode.run(AlarmPointNode.java:62)
at java.lang.Thread.run(Thread.java:595)
Reproduction
===========
Configure one broker to listen to http://localhost:50000 and the other broker
to list to http://localhost:50001. Network the brokers together using the
SimpleDiscoveryAgent (static) configuration:
<broker brokerName="broker1" persistent="false" useJmx="false">
<networkConnectors>
<networkConnector uri="static:(http://localhost:50001)"/>
</networkConnectors>
<persistenceAdapter>
<memoryPersistenceAdapter/>
</persistenceAdapter>
<transportConnectors>
<transportConnector uri="http://localhost:50000"/>
</transportConnectors>
</broker>
and the other broker as:
<broker brokerName="broker2" persistent="false" useJmx="false">
<networkConnectors>
<networkConnector uri="static:(http://localhost:50000)"/>
</networkConnectors>
<persistenceAdapter>
<memoryPersistenceAdapter/>
</persistenceAdapter>
<transportConnectors>
<transportConnector uri="http://localhost:50001"/>
</transportConnectors>
</broker>
Start broker1, but do not start broker2. Observe the stacktrace in broker1's
logs.
Cause
======
During startup, the following code executes in
DiscoveryNetworkConnector#onServiceAdd(DiscoveryEvent event):
NetworkBridge bridge = createBridge(localTransport,
remoteTransport, event);
try {
bridge.start();
bridges.put(uri, bridge);
} catch (Exception e) {
ServiceSupport.dispose(localTransport);
ServiceSupport.dispose(remoteTransport);
LOG.warn("Could not start network bridge between: " +
localURIName + " and: " + uri + " due to: " + e);
A bridge is created to connect broker1 to broker2 (http://localhost:50000 to
http://localhost:50001), but since broker2 is not started, bridge.start() will
throw a "Connection refused" exception. In handling this exception,
ServiceSupport.dispose(remoteTransport) is called, which eventually calls
through to HttpClientTransport#doStop(ServiceStopper stopper):
protected void doStop(ServiceStopper stopper) throws Exception {
httpMethod.abort();
}
The NPE is caused becuase httpMethod is null.
When bridge.start() is called, it will pass through to
HttpClientTransport#doStart():
LOG.trace("HTTP GET consumer thread starting: " + this);
HttpClient httpClient = getReceiveHttpClient();
URI remoteUrl = getRemoteUrl();
HeadMethod httpMethod = new HeadMethod(remoteUrl.toString());
configureMethod(httpMethod);
int answer = httpClient.executeMethod(httpMethod);
The httpClient.executeMethod(httpMethod) throws the "connection refused"
exception because the HEAD command cannot connect. The httpMethod in doStart()
is a local var, while the object-scope httpMethod is only set once the
transport starts running, which never occurs due to the HEAD failure.
Solution
=======
Check that httpMethod is not null before disposing:
protected void doStop(ServiceStopper stopper) throws Exception {
if(httpMethod != null)
{
httpMethod.abort();
}
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.