activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From numpty <roger...@gmail.com>
Subject ActiveMQ CMS - Unhandled exception during session close after a Transport exception
Date Wed, 05 Sep 2007 14:13:25 GMT

Sorry, resent with code example...

Does anyone have any advice on how to cleanly close a session when comms to
a broker is broken?

After the comms have been broken (shutting down the broker is an easy way to
reproduce) and the producer attempts to send a message a Transport IO
exception is raised but after this point the session cannot be cleanly
closed. The sessions closed flag indicates it is not already closed. The
problem seems to be mainly in the BufferedOutputStream - this objects
"close" method is called but after this the same objects "flush" method is
called resulting in attempts to access deleted memory. I'm presuming it is
attempting to send cached data after the stream has been closed.

This is ActiveMQ-CPP 2.1, using Broker version 5.0 snapshot (To get around
the expired messages not being removed from the queue bug)

The following is a snippet of the code which demonstrates this problem:

static Connection* connection = NULL;
static Session* session = NULL;
static Destination* destination = NULL;
static MessageProducer* producer = NULL;

static const std::string brokerURI =
"tcp://127.0.0.1:61616?wireFormat=openwire&transport.useAsyncSend=true&connectionTimeout=5000&soTimeout=1000";

bool initialise()
{
	bool result = false;

	try {
		ActiveMQConnectionFactory* connectionFactory = new
ActiveMQConnectionFactory( brokerURI );

		// Create a Connection
		connection = connectionFactory->createConnection();
		connection->start();

		delete connectionFactory;

		// Create a Session
		session = connection->createSession( Session::AUTO_ACKNOWLEDGE );

		// Create the destination
		destination = session->createQueue( "BARNEY" );

		// Create a MessageProducer from the Session to the Queue
		producer = session->createProducer( destination );
		producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT);

		result = true;
	}
	catch (activemq::exceptions::ActiveMQException& e) {
		e.printStackTrace();
	}

	return result;
}


bool sendMessage(string msg)
{
	bool result = false;

    try {
	    TextMessage* message = session->createTextMessage( msg );

             producer->send( message );
	     delete message;
		
	     result = true;
	}
	catch (activemq::exceptions::ActiveMQException& e) { // <------<<<< catches
the TransportIOException after the broker has been shutdown (transport is
closed)
		// Close open resources.
		try{
			if( session != NULL ){
				session->close();  // <--------<<<< Causes unhandled exceptions
			}
            // close connection...
			// free everything else...
		}
	}

	return result;
}

void main()
{
	if (initialise()){
		while (1){
			// do things to create the data to send...

			// <<<< KILL THE BROKER SOMETIME DURING THIS LOOP >>>>

			// send data
			sendMessage("fred");
		}

		// clean up .....
	}
}


Thanks

-- 
View this message in context: http://www.nabble.com/ActiveMQ-CMS---Unhandled-exception-during-session-close-after-a-Transport-exception-tf4384057s2354.html#a12497913
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message