Skip to content
Snippets Groups Projects
Commit 98dcb681 authored by Elvin Alin Sindrilaru's avatar Elvin Alin Sindrilaru
Browse files

XROOTD: Catch the right exception type and simplify a bit the clean-up logic in

        case an exception is thrown
parent f1952502
No related branches found
No related tags found
No related merge requests found
...@@ -194,29 +194,24 @@ XrdxCastorClient::SendAsyncRequest(const std::string& userId, ...@@ -194,29 +194,24 @@ XrdxCastorClient::SendAsyncRequest(const std::string& userId,
// Lock the map as we could receive the answer for our request before registering // Lock the map as we could receive the answer for our request before registering
// it to the map. This is fine as the request is processed only after we get the ack. // it to the map. This is fine as the request is processed only after we get the ack.
mMutexMaps.Lock(); // --> mMutexMaps.Lock(); // -->
castor::MessageAck* ack;
try try
{ {
// Wait for acknowledgment // Wait for acknowledgment
castor::IObject* obj = sock.readObject(); castor::IObject* obj = sock.readObject();
castor::MessageAck* ack = dynamic_cast<castor::MessageAck*>(obj); ack = dynamic_cast<castor::MessageAck*>(obj);
if (0 == ack) if (0 == ack)
{ {
mMutexMaps.UnLock(); // <--
castor::exception::InvalidArgument e; castor::exception::InvalidArgument e;
e.getMessage() << "No Acknowledgement from the server"; e.getMessage() << "No Acknowledgement from the server";
delete ack;
delete elem;
throw e; throw e;
} }
if (!ack->status()) if (!ack->status())
{ {
mMutexMaps.UnLock(); // <--
castor::exception::Exception e(ack->errorCode()); castor::exception::Exception e(ack->errorCode());
e.getMessage() << ack->errorMessage(); e.getMessage() << ack->errorMessage();
delete ack;
delete elem;
throw e; throw e;
} }
...@@ -241,34 +236,28 @@ XrdxCastorClient::SendAsyncRequest(const std::string& userId, ...@@ -241,34 +236,28 @@ XrdxCastorClient::SendAsyncRequest(const std::string& userId,
{ {
// If user exists already, remove the request from the map // If user exists already, remove the request from the map
mMapRequests.erase(req_insert.first); mMapRequests.erase(req_insert.first);
mMutexMaps.UnLock(); // <--
castor::exception::Internal e; castor::exception::Internal e;
e.getMessage() << "Fatal error: the user we are trying to register " e.getMessage() << "Fatal error: the user we are trying to register "
<< "exists already in the map "; << "exists already in the map ";
delete elem;
delete ack;
throw e; throw e;
} }
} }
else else
{ {
mMutexMaps.UnLock(); // <--
castor::exception::Internal e; castor::exception::Internal e;
e.getMessage() << "Fatal error: the request we are trying to submit " e.getMessage() << "Fatal error: the request we are trying to submit "
<< "exists already in the map "; << "exists already in the map ";
delete elem;
delete ack;
throw e; throw e;
} }
mMutexMaps.UnLock(); // <-- mMutexMaps.UnLock(); // <--
delete ack; delete ack;
} }
catch (castor::exception::Communication e) catch (castor::exception::Exception& e)
{ {
// Unlock the map and forward any exception
mMutexMaps.UnLock(); // <-- mMutexMaps.UnLock(); // <--
e.getMessage() << "Reading object from the socket failed"; delete ack;
delete elem; delete elem;
throw e; throw e;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment