You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by Olivier Langlois <Ol...@streamtheworld.com> on 2009/11/16 23:39:09 UTC

ResponseCorrelator::request() exception safety concern in SVN trunk

Hi,

It seems to me that since the function oneway() and futureResponse::getResponse() can throw exceptions, the code should make sure that the requestMap is cleared in all cases. I would propose something like:

try
{
        // Send the request.
        next->oneway( command );

        // Get the response.
        response = futureResponse->getResponse( timeout );
}
catch(.)
{
        // Perform cleanup on the map.
        synchronized( &mapMutex ){

            // We do not want memory corruption by accessing freed
            // futureResponse objects by accident in onCommand() - get this thing out
            // of the map.
            requestMap.erase( command->getCommandId() );
        }
       throw;
}
synchronized( &mapMutex ){

    // We've done our waiting - get this thing out
    // of the map.
    requestMap.erase( command->getCommandId() );
}

Olivier Langlois
C++ Technical Lead

STREAMTHEWORLD

t. 1 866 448 4037 ext. 675
t. 1 514 448 4037 ext. 675
f. 1 514 807 1861

olivier.langlois@streamtheworld.com
streamtheworld.com
 
StreamTheWorld launches its new BlackBerry application. Learn more


Re: ResponseCorrelator::request() exception safety concern in SVN trunk

Posted by Timothy Bish <ta...@gmail.com>.
On Mon, 2009-11-16 at 17:39 -0500, Olivier Langlois wrote:
> Hi,
> 
> It seems to me that since the function oneway() and futureResponse::getResponse() can throw exceptions, the code should make sure that the requestMap is cleared in all cases. I would propose something like:
> 
> try
> {
>         // Send the request.
>         next->oneway( command );
> 
>         // Get the response.
>         response = futureResponse->getResponse( timeout );
> }
> catch(.)
> {
>         // Perform cleanup on the map.
>         synchronized( &mapMutex ){
> 
>             // We do not want memory corruption by accessing freed
>             // futureResponse objects by accident in onCommand() - get this thing out
>             // of the map.
>             requestMap.erase( command->getCommandId() );
>         }
>        throw;
> }
> synchronized( &mapMutex ){
> 
>     // We've done our waiting - get this thing out
>     // of the map.
>     requestMap.erase( command->getCommandId() );
> }
> 
> Olivier Langlois
> C++ Technical Lead
> 
> STREAMTHEWORLD
> 
> t. 1 866 448 4037 ext. 675
> t. 1 514 448 4037 ext. 675
> f. 1 514 807 1861
> 
> olivier.langlois@streamtheworld.com
> streamtheworld.com
>  
> StreamTheWorld launches its new BlackBerry application. Learn more
> 

Your best bet is to open a new Jira issue to document the issue so that
it doesn't get lost on the mailing list.

Regards
Tim.


-- 
Tim Bish
http://fusesource.com
http://timbish.blogspot.com/