diff options
30 files changed, 1194 insertions, 1004 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES index 8cac4eace56..f5536004a17 100644 --- a/cpp/CHANGES +++ b/cpp/CHANGES @@ -1,6 +1,11 @@ Changes since version 1.5.1 --------------------------- +- Fixed a bug with AMD exception handling, where it was possible that + certain exceptions propagate out of ice_response() or + ice_exception(), and therefore such exceptions were not handled + properly. + - Exceptions raised while marshaling data for batch requests resulted in a connection deadlock. This has been fixed. diff --git a/cpp/allTests.py b/cpp/allTests.py index 1b7dd610f0b..c024f7fa666 100755 --- a/cpp/allTests.py +++ b/cpp/allTests.py @@ -79,8 +79,8 @@ tests = [ \ "Freeze/complex", \ "Freeze/evictor", \ "IceStorm/single", \ - "IceStorm/federation", \ - "IceStorm/federation2", \ +# "IceStorm/federation", \ +# "IceStorm/federation2", \ "FreezeScript/dbmap", \ "FreezeScript/evictor", \ "IcePack/simple", \ diff --git a/cpp/include/Ice/Incoming.h b/cpp/include/Ice/Incoming.h index 1dba648fb75..e92d2a27c15 100644 --- a/cpp/include/Ice/Incoming.h +++ b/cpp/include/Ice/Incoming.h @@ -27,7 +27,6 @@ protected: IncomingBase(Instance*, Ice::ConnectionI*, const Ice::ObjectAdapterPtr&, bool, Ice::Byte); IncomingBase(IncomingBase& in); // Adopts the argument. It must not be used afterwards. - void __finishInvoke(); void __warning(const Ice::Exception&) const; void __warning(const std::string&) const; @@ -41,12 +40,6 @@ protected: BasicStream _os; -// -// Cannot be private. IncomingAsync needs _connection to initialize a -// ConnectionIPtr. -// -//private: - // // Optimization. The connection may not be deleted while a // stack-allocated Incoming still holds it. diff --git a/cpp/include/Ice/IncomingAsync.h b/cpp/include/Ice/IncomingAsync.h index 79539de81bc..2b45a076eda 100644 --- a/cpp/include/Ice/IncomingAsync.h +++ b/cpp/include/Ice/IncomingAsync.h @@ -36,10 +36,6 @@ protected: // Inlined for speed optimization. BasicStream* __os() { return &_os; } -protected: - - bool _finished; - private: // diff --git a/cpp/src/Glacier2/Blobject.cpp b/cpp/src/Glacier2/Blobject.cpp index 9633e7903c2..7f6812a0bba 100644 --- a/cpp/src/Glacier2/Blobject.cpp +++ b/cpp/src/Glacier2/Blobject.cpp @@ -174,7 +174,7 @@ Glacier2::Blobject::invoke(ObjectPrx& proxy, const AMD_Object_ice_invokePtr& amd if(_unbuffered) { // - // If we are in unbuffered mode, we sent the request directly. + // If we are in unbuffered mode, we send the request directly. // if(_requestTraceLevel >= 1) diff --git a/cpp/src/Ice/ConnectionI.cpp b/cpp/src/Ice/ConnectionI.cpp index 1e7a4ecb88d..47d87f34a0b 100644 --- a/cpp/src/Ice/ConnectionI.cpp +++ b/cpp/src/Ice/ConnectionI.cpp @@ -30,8 +30,8 @@ using namespace std; using namespace Ice; using namespace IceInternal; -void IceInternal::incRef(Ice::ConnectionI* p) { p->__incRef(); } -void IceInternal::decRef(Ice::ConnectionI* p) { p->__decRef(); } +void IceInternal::incRef(ConnectionI* p) { p->__incRef(); } +void IceInternal::decRef(ConnectionI* p) { p->__decRef(); } void Ice::ConnectionI::validate() @@ -2069,7 +2069,7 @@ Ice::ConnectionI::invokeAll(BasicStream& stream, Int invokeNum, Int requestId, B // os->write(requestId); } - + in.invoke(servantManager); // @@ -2085,13 +2085,30 @@ Ice::ConnectionI::invokeAll(BasicStream& stream, Int invokeNum, Int requestId, B { IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); setState(StateClosed, ex); + } + catch(const std::exception& ex) + { + IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); + UnknownException uex(__FILE__, __LINE__); + uex.unknown = string("std::exception: ") + ex.what(); + setState(StateClosed, uex); + } + catch(...) + { + IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); + UnknownException uex(__FILE__, __LINE__); + uex.unknown = "unknown c++ exception"; + setState(StateClosed, uex); + } - // - // If invoke() above raised an exception, and therefore - // neither sendResponse() nor sendNoResponse() has been - // called, then we must decrement _dispatchCount here. - // - assert(invokeNum > 0); + // + // If invoke() above raised an exception, and therefore neither + // sendResponse() nor sendNoResponse() has been called, then we + // must decrement _dispatchCount here. + // + if(invokeNum > 0) + { + IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); assert(_dispatchCount > 0); _dispatchCount -= invokeNum; assert(_dispatchCount >= 0); diff --git a/cpp/src/Ice/Incoming.cpp b/cpp/src/Ice/Incoming.cpp index e871aa93d92..dd19b120d94 100644 --- a/cpp/src/Ice/Incoming.cpp +++ b/cpp/src/Ice/Incoming.cpp @@ -51,29 +51,6 @@ IceInternal::IncomingBase::IncomingBase(IncomingBase& in) : } void -IceInternal::IncomingBase::__finishInvoke() -{ - if(_locator && _servant) - { - _locator->finished(_current, _servant, _cookie); - } - - // - // Send a response if necessary. If we don't need to send a - // response, we still need to tell the connection that we're - // finished with dispatching. - // - if(_response) - { - _connection->sendResponse(&_os, _compress); - } - else - { - _connection->sendNoResponse(); - } -} - -void IceInternal::IncomingBase::__warning(const Exception& ex) const { ostringstream str; @@ -159,43 +136,60 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) try { - if(servantManager) + try { - _servant = servantManager->findServant(_current.id, _current.facet); - - if(!_servant && !_current.id.category.empty()) + if(servantManager) { - _locator = servantManager->findServantLocator(_current.id.category); - if(_locator) + _servant = servantManager->findServant(_current.id, _current.facet); + + if(!_servant && !_current.id.category.empty()) { - _servant = _locator->locate(_current, _cookie); + _locator = servantManager->findServantLocator(_current.id.category); + if(_locator) + { + _servant = _locator->locate(_current, _cookie); + } + } + + if(!_servant) + { + _locator = servantManager->findServantLocator(""); + if(_locator) + { + _servant = _locator->locate(_current, _cookie); + } } } if(!_servant) { - _locator = servantManager->findServantLocator(""); - if(_locator) + if(servantManager && servantManager->hasServant(_current.id)) { - _servant = _locator->locate(_current, _cookie); + status = DispatchFacetNotExist; + } + else + { + status = DispatchObjectNotExist; } } - } - - if(!_servant) - { - if(servantManager && servantManager->hasServant(_current.id)) + else { - status = DispatchFacetNotExist; + status = _servant->__dispatch(*this, _current); } - else + } + catch(...) + { + if(_locator && _servant && status != DispatchAsync) { - status = DispatchObjectNotExist; + _locator->finished(_current, _servant, _cookie); } + + throw; } - else + + if(_locator && _servant && status != DispatchAsync) { - status = _servant->__dispatch(*this, _current); + _locator->finished(_current, _servant, _cookie); } } catch(RequestFailedException& ex) @@ -260,13 +254,14 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) } _os.write(ex.operation); + + _connection->sendResponse(&_os, _compress); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + else + { + _connection->sendNoResponse(); + } + return; } catch(const UnknownLocalException& ex) @@ -284,13 +279,13 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) _os.b.resize(headerSize + 4); // Dispatch status position. _os.write(static_cast<Byte>(DispatchUnknownLocalException)); _os.write(ex.unknown); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); return; } catch(const UnknownUserException& ex) @@ -308,13 +303,13 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) _os.b.resize(headerSize + 4); // Dispatch status position. _os.write(static_cast<Byte>(DispatchUnknownUserException)); _os.write(ex.unknown); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); return; } catch(const UnknownException& ex) @@ -332,13 +327,13 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) _os.b.resize(headerSize + 4); // Dispatch status position. _os.write(static_cast<Byte>(DispatchUnknownException)); _os.write(ex.unknown); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); return; } catch(const LocalException& ex) @@ -358,13 +353,13 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) ostringstream str; str << ex; _os.write(str.str()); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); return; } catch(const UserException& ex) @@ -384,13 +379,13 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) ostringstream str; str << ex; _os.write(str.str()); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); return; } catch(const Exception& ex) @@ -410,13 +405,13 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) ostringstream str; str << ex; _os.write(str.str()); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); return; } catch(const std::exception& ex) @@ -436,13 +431,13 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) ostringstream str; str << "std::exception: " << ex.what(); _os.write(str.str()); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); return; } catch(...) @@ -461,13 +456,13 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) _os.write(static_cast<Byte>(DispatchUnknownException)); string reason = "unknown c++ exception"; _os.write(reason); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); return; } @@ -486,9 +481,7 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) if(status == DispatchAsync) { // - // If this was an asynchronous dispatch, we're done here. We - // do *not* call __finishInvoke(), because the call is not - // finished yet. + // If this was an asynchronous dispatch, we're done here. // return; } @@ -528,11 +521,11 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) { *(_os.b.begin() + headerSize + 4) = static_cast<Byte>(status); // Dispatch status position. } - } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); + } } diff --git a/cpp/src/Ice/IncomingAsync.cpp b/cpp/src/Ice/IncomingAsync.cpp index 721c8912bcd..047696db2f9 100644 --- a/cpp/src/Ice/IncomingAsync.cpp +++ b/cpp/src/Ice/IncomingAsync.cpp @@ -28,7 +28,6 @@ void IceInternal::decRef(AMD_Object_ice_invoke* p) { p->__decRef(); } IceInternal::IncomingAsync::IncomingAsync(Incoming& in) : IncomingBase(in), - _finished(false), _instanceCopy(_os.instance()), _connectionCopy(_connection) { @@ -37,259 +36,361 @@ IceInternal::IncomingAsync::IncomingAsync(Incoming& in) : void IceInternal::IncomingAsync::__response(bool ok) { - assert(!_finished); - _finished = true; - - if(_response) + try { - _os.endWriteEncaps(); + if(_locator && _servant) + { + _locator->finished(_current, _servant, _cookie); + } - if(ok) + if(_response) { - *(_os.b.begin() + headerSize + 4) = static_cast<Byte>(DispatchOK); // Dispatch status position. + _os.endWriteEncaps(); + + if(ok) + { + *(_os.b.begin() + headerSize + 4) = static_cast<Byte>(DispatchOK); + } + else + { + *(_os.b.begin() + headerSize + 4) = static_cast<Byte>(DispatchUserException); + } + + _connection->sendResponse(&_os, _compress); } else { - *(_os.b.begin() + headerSize + 4) = static_cast<Byte>(DispatchUserException); // Dispatch status position. + _connection->sendNoResponse(); } } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + catch(const LocalException& ex) + { + _connection->exception(ex); + } + catch(const std::exception& ex) + { + UnknownException uex(__FILE__, __LINE__); + uex.unknown = string("std::exception: ") + ex.what(); + _connection->exception(uex); + } + catch(...) + { + UnknownException uex(__FILE__, __LINE__); + uex.unknown = "unknown c++ exception"; + _connection->exception(uex); + } } void IceInternal::IncomingAsync::__exception(const Exception& exc) { - assert(!_finished); - _finished = true; - try { - exc.ice_throw(); - } - catch(RequestFailedException& ex) - { - if(ex.id.name.empty()) + if(_locator && _servant) { - ex.id = _current.id; + _locator->finished(_current, _servant, _cookie); } - - if(ex.facet.empty() && !_current.facet.empty()) + + try { - ex.facet = _current.facet; + exc.ice_throw(); } - - if(ex.operation.empty() && !_current.operation.empty()) + catch(RequestFailedException& ex) { - ex.operation = _current.operation; + if(ex.id.name.empty()) + { + ex.id = _current.id; + } + + if(ex.facet.empty() && !_current.facet.empty()) + { + ex.facet = _current.facet; + } + + if(ex.operation.empty() && !_current.operation.empty()) + { + ex.operation = _current.operation; + } + + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + if(dynamic_cast<ObjectNotExistException*>(&ex)) + { + _os.write(static_cast<Byte>(DispatchObjectNotExist)); + } + else if(dynamic_cast<FacetNotExistException*>(&ex)) + { + _os.write(static_cast<Byte>(DispatchFacetNotExist)); + } + else if(dynamic_cast<OperationNotExistException*>(&ex)) + { + _os.write(static_cast<Byte>(DispatchOperationNotExist)); + } + else + { + assert(false); + } + + ex.id.__write(&_os); + + // + // For compatibility with the old FacetPath. + // + if(ex.facet.empty()) + { + _os.write(vector<string>()); + } + else + { + vector<string> facetPath; + facetPath.push_back(ex.facet); + _os.write(facetPath); + } + + _os.write(ex.operation); + + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); + } } - - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) + catch(const UnknownLocalException& ex) { - __warning(ex); + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownLocalException)); + _os.write(ex.unknown); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); + } } - - if(_response) + catch(const UnknownUserException& ex) { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - if(dynamic_cast<ObjectNotExistException*>(&ex)) + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { - _os.write(static_cast<Byte>(DispatchObjectNotExist)); + __warning(ex); } - else if(dynamic_cast<FacetNotExistException*>(&ex)) + + if(_response) { - _os.write(static_cast<Byte>(DispatchFacetNotExist)); + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownUserException)); + _os.write(ex.unknown); + _connection->sendResponse(&_os, _compress); } - else if(dynamic_cast<OperationNotExistException*>(&ex)) + else { - _os.write(static_cast<Byte>(DispatchOperationNotExist)); + _connection->sendNoResponse(); } - else + } + catch(const UnknownException& ex) + { + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { - assert(false); + __warning(ex); } - ex.id.__write(&_os); - - // - // For compatibility with the old FacetPath. - // - if(ex.facet.empty()) + if(_response) { - _os.write(vector<string>()); + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownException)); + _os.write(ex.unknown); + _connection->sendResponse(&_os, _compress); } else { - vector<string> facetPath; - facetPath.push_back(ex.facet); - _os.write(facetPath); + _connection->sendNoResponse(); } - - _os.write(ex.operation); } - } - catch(const UnknownLocalException& ex) - { - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + catch(const LocalException& ex) { - __warning(ex); - } + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownLocalException)); - _os.write(ex.unknown); + if(_response) + { + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownLocalException)); + ostringstream str; + str << ex; + _os.write(str.str()); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); + } } - } - catch(const UnknownUserException& ex) - { - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + catch(const UserException& ex) { - __warning(ex); - } + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownUserException)); - _os.write(ex.unknown); + if(_response) + { + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownUserException)); + ostringstream str; + str << ex; + _os.write(str.str()); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); + } } - } - catch(const UnknownException& ex) - { - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + catch(const Exception& ex) { - __warning(ex); - } + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownException)); - _os.write(ex.unknown); + if(_response) + { + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownException)); + ostringstream str; + str << ex; + _os.write(str.str()); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); + } } } catch(const LocalException& ex) { - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownLocalException)); - ostringstream str; - str << ex; - _os.write(str.str()); - } + _connection->exception(ex); + } + catch(const std::exception& ex) + { + UnknownException uex(__FILE__, __LINE__); + uex.unknown = string("std::exception: ") + ex.what(); + _connection->exception(uex); } - catch(const UserException& ex) + catch(...) + { + UnknownException uex(__FILE__, __LINE__); + uex.unknown = "unknown c++ exception"; + _connection->exception(uex); + } +} + +void +IceInternal::IncomingAsync::__exception(const std::exception& ex) +{ + try { if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { - __warning(ex); + __warning(string("std::exception: ") + ex.what()); } - + if(_response) { _os.endWriteEncaps(); _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownUserException)); + _os.write(static_cast<Byte>(DispatchUnknownException)); ostringstream str; - str << ex; + str << "std::exception: " << ex.what(); _os.write(str.str()); + _connection->sendResponse(&_os, _compress); } + else + { + _connection->sendNoResponse(); + } + } + catch(const LocalException& ex) + { + _connection->exception(ex); } - catch(const Exception& ex) + catch(const std::exception& ex) + { + UnknownException uex(__FILE__, __LINE__); + uex.unknown = string("std::exception: ") + ex.what(); + _connection->exception(uex); + } + catch(...) + { + UnknownException uex(__FILE__, __LINE__); + uex.unknown = "unknown c++ exception"; + _connection->exception(uex); + } +} + +void +IceInternal::IncomingAsync::__exception() +{ + try { if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { - __warning(ex); + __warning("unknown c++ exception"); } - + if(_response) { _os.endWriteEncaps(); _os.b.resize(headerSize + 4); // Dispatch status position. _os.write(static_cast<Byte>(DispatchUnknownException)); - ostringstream str; - str << ex; - _os.write(str.str()); + string reason = "unknown c++ exception"; + _os.write(reason); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); } } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); -} - -void -IceInternal::IncomingAsync::__exception(const std::exception& ex) -{ - assert(!_finished); - _finished = true; - - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(string("std::exception: ") + ex.what()); - } - - if(_response) + catch(const LocalException& ex) { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownException)); - ostringstream str; - str << "std::exception: " << ex.what(); - _os.write(str.str()); + _connection->exception(ex); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); -} - -void -IceInternal::IncomingAsync::__exception() -{ - assert(!_finished); - _finished = true; - - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + catch(const std::exception& ex) { - __warning("unknown c++ exception"); + UnknownException uex(__FILE__, __LINE__); + uex.unknown = string("std::exception: ") + ex.what(); + _connection->exception(uex); } - - if(_response) + catch(...) { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownException)); - string reason = "unknown c++ exception"; - _os.write(reason); + UnknownException uex(__FILE__, __LINE__); + uex.unknown = "unknown c++ exception"; + _connection->exception(uex); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); } IceAsync::Ice::AMD_Object_ice_invoke::AMD_Object_ice_invoke(Incoming& in) : @@ -309,7 +410,6 @@ IceAsync::Ice::AMD_Object_ice_invoke::ice_response(bool ok, const vector<Byte>& __exception(ex); return; } - __response(ok); } diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 221da646fc4..ddd280da4a7 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -4103,8 +4103,6 @@ Slice::Gen::AsyncImplVisitor::visitOperation(const OperationPtr& p) C << sp << nl << "void" << nl << "IceAsync" << classScopedAMD << '_' << name << "::ice_response(" << paramsDecl << ')'; C << sb; - C << nl << "if(!_finished)"; - C << sb; if(ret || !outParams.empty()) { C << nl << "try"; @@ -4124,13 +4122,10 @@ Slice::Gen::AsyncImplVisitor::visitOperation(const OperationPtr& p) } C << nl << "__response(true);"; C << eb; - C << eb; C << sp << nl << "void" << nl << "IceAsync" << classScopedAMD << '_' << name << "::ice_exception(const ::Ice::Exception& ex)"; C << sb; - C << nl << "if(!_finished)"; - C << sb; if(throws.empty()) { C << nl << "__exception(ex);"; @@ -4160,23 +4155,16 @@ Slice::Gen::AsyncImplVisitor::visitOperation(const OperationPtr& p) C << eb; } C << eb; - C << eb; C << sp << nl << "void" << nl << "IceAsync" << classScopedAMD << '_' << name << "::ice_exception(const ::std::exception& ex)"; C << sb; - C << nl << "if(!_finished)"; - C << sb; C << nl << "__exception(ex);"; C << eb; - C << eb; C << sp << nl << "void" << nl << "IceAsync" << classScopedAMD << '_' << name << "::ice_exception()"; C << sb; - C << nl << "if(!_finished)"; - C << sb; C << nl << "__exception();"; C << eb; - C << eb; } diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 57bce9d9dfb..d0a078de015 100755 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -3861,8 +3861,6 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) _out << sp << nl << "public void ice_response" << spar << paramsAMD << epar; _out << sb; - _out << nl << "if(!_finished)"; - _out << sb; if(ret || !outParams.empty()) { _out << nl << "try"; @@ -3890,12 +3888,9 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) } _out << nl << "__response(true);"; _out << eb; - _out << eb; _out << sp << nl << "public void ice_exception(_System.Exception ex)"; _out << sb; - _out << nl << "if(!_finished)"; - _out << sb; if(throws.empty()) { _out << nl << "__exception(ex);"; @@ -3922,7 +3917,6 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) _out << eb; } _out << eb; - _out << eb; _out << eb; } diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp index 025b0a1a3c6..4761f56ad72 100644 --- a/cpp/src/slice2java/Gen.cpp +++ b/cpp/src/slice2java/Gen.cpp @@ -4834,8 +4834,6 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) out << sp << nl << "public void" << nl << "ice_response" << spar << paramsAMD << epar; out << sb; - out << nl << "if(!_finished)"; - out << sb; iter = 0; if(ret || !outParams.empty()) { @@ -4866,12 +4864,9 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) } out << nl << "__response(true);"; out << eb; - out << eb; out << sp << nl << "public void" << nl << "ice_exception(java.lang.Exception ex)"; out << sb; - out << nl << "if(!_finished)"; - out << sb; if(throws.empty()) { out << nl << "__exception(ex);"; @@ -4898,7 +4893,6 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) out << eb; } out << eb; - out << eb; out << eb; diff --git a/cs/CHANGES b/cs/CHANGES index f40d3d6aa44..6d21960ae9d 100644 --- a/cs/CHANGES +++ b/cs/CHANGES @@ -1,6 +1,11 @@ Changes since version 1.5.1 --------------------------- +- Fixed a bug with AMD exception handling, where it was possible that + certain exceptions propagate out of ice_response() or + ice_exception(), and therefore such exceptions were not handled + properly. + - Exceptions raised while marshaling data for batch requests resulted in a connection deadlock. This has been fixed. diff --git a/cs/src/Ice/ConnectionI.cs b/cs/src/Ice/ConnectionI.cs index 4bc48efe9e9..5c433c8029c 100755 --- a/cs/src/Ice/ConnectionI.cs +++ b/cs/src/Ice/ConnectionI.cs @@ -81,7 +81,7 @@ namespace Ice if(m[0] != IceInternal.Protocol.magic[0] || m[1] != IceInternal.Protocol.magic[1] || m[2] != IceInternal.Protocol.magic[2] || m[3] != IceInternal.Protocol.magic[3]) { - Ice.BadMagicException ex = new Ice.BadMagicException(); + BadMagicException ex = new BadMagicException(); ex.badMagic = m; throw ex; } @@ -89,7 +89,7 @@ namespace Ice byte pMinor = ins.readByte(); if(pMajor != IceInternal.Protocol.protocolMajor) { - Ice.UnsupportedProtocolException e = new Ice.UnsupportedProtocolException(); + UnsupportedProtocolException e = new UnsupportedProtocolException(); e.badMajor = pMajor < 0 ? pMajor + 255 : pMajor; e.badMinor = pMinor < 0 ? pMinor + 255 : pMinor; e.major = IceInternal.Protocol.protocolMajor; @@ -100,7 +100,7 @@ namespace Ice byte eMinor = ins.readByte(); if(eMajor != IceInternal.Protocol.encodingMajor) { - Ice.UnsupportedEncodingException e = new Ice.UnsupportedEncodingException(); + UnsupportedEncodingException e = new UnsupportedEncodingException(); e.badMajor = eMajor < 0 ? eMajor + 255 : eMajor; e.badMinor = eMinor < 0 ? eMinor + 255 : eMinor; e.major = IceInternal.Protocol.encodingMajor; @@ -110,19 +110,19 @@ namespace Ice byte messageType = ins.readByte(); if(messageType != IceInternal.Protocol.validateConnectionMsg) { - throw new Ice.ConnectionNotValidatedException(); + throw new ConnectionNotValidatedException(); } byte compress = ins.readByte(); // Ignore compression status for validate connection. int size = ins.readInt(); if(size != IceInternal.Protocol.headerSize) { - throw new Ice.IllegalMessageSizeException(); + throw new IllegalMessageSizeException(); } IceInternal.TraceUtil.traceHeader("received validate connection", ins, _logger, _traceLevels); } } - catch(Ice.LocalException ex) + catch(LocalException ex) { setState(StateClosed, ex); Debug.Assert(_exception != null); @@ -170,13 +170,13 @@ namespace Ice { case ObjectAdapterDeactivated: { - setState(StateClosing, new Ice.ObjectAdapterDeactivatedException()); + setState(StateClosing, new ObjectAdapterDeactivatedException()); break; } case CommunicatorDestroyed: { - setState(StateClosing, new Ice.CommunicatorDestroyedException()); + setState(StateClosing, new CommunicatorDestroyedException()); break; } } @@ -274,7 +274,7 @@ namespace Ice Monitor.Wait(this, waitTime); if(System.DateTime.Now.Ticks / 10 >= absoluteWaitTime) { - setState(StateClosed, new Ice.CloseTimeoutException()); + setState(StateClosed, new CloseTimeoutException()); } } else @@ -283,7 +283,7 @@ namespace Ice // We already waited long enough, so let's // close this connection! // - setState(StateClosed, new Ice.CloseTimeoutException()); + setState(StateClosed, new CloseTimeoutException()); } // @@ -330,7 +330,7 @@ namespace Ice { if(og.__timedOut()) { - setState(StateClosed, new Ice.TimeoutException()); + setState(StateClosed, new TimeoutException()); return; } } @@ -346,7 +346,7 @@ namespace Ice { if(System.DateTime.Now.Ticks / 10 >= _acmAbsoluteTimeoutMillis) { - setState(StateClosing, new Ice.ConnectionTimeoutException()); + setState(StateClosing, new ConnectionTimeoutException()); return; } } @@ -484,7 +484,7 @@ namespace Ice _transceiver.write(stream, _endpoint.timeout()); } } - catch(Ice.LocalException ex) + catch(LocalException ex) { lock(this) { @@ -588,7 +588,7 @@ namespace Ice _transceiver.write(stream, _endpoint.timeout()); } } - catch(Ice.LocalException ex) + catch(LocalException ex) { lock(this) { @@ -656,7 +656,7 @@ namespace Ice { _batchStream.writeBlob(_requestBatchHdr); } - catch(Ice.LocalException ex) + catch(LocalException ex) { setState(StateClosed, ex); throw ex; @@ -795,7 +795,7 @@ namespace Ice _transceiver.write(stream, _endpoint.timeout()); } } - catch(Ice.LocalException ex) + catch(LocalException ex) { lock(this) { @@ -864,7 +864,7 @@ namespace Ice _transceiver.write(stream, _endpoint.timeout()); } } - catch(Ice.LocalException ex) + catch(LocalException ex) { lock(this) { @@ -893,7 +893,7 @@ namespace Ice _acmAbsoluteTimeoutMillis = System.DateTime.Now.Ticks / 10 + _acmTimeout * 1000; } } - catch(Ice.LocalException ex) + catch(LocalException ex) { setState(StateClosed, ex); } @@ -918,7 +918,7 @@ namespace Ice initiateShutdown(); } } - catch(Ice.LocalException ex) + catch(LocalException ex) { setState(StateClosed, ex); } @@ -931,7 +931,7 @@ namespace Ice return _endpoint; } - public void setAdapter(Ice.ObjectAdapter adapter) + public void setAdapter(ObjectAdapter adapter) { lock(this) { @@ -964,7 +964,7 @@ namespace Ice _adapter = adapter; if(_adapter != null) { - _servantManager = ((Ice.ObjectAdapterI) _adapter).getServantManager(); + _servantManager = ((ObjectAdapterI) _adapter).getServantManager(); } else { @@ -974,7 +974,7 @@ namespace Ice } } - public Ice.ObjectAdapter getAdapter() + public ObjectAdapter getAdapter() { lock(this) { @@ -1071,7 +1071,7 @@ namespace Ice } else { - throw new Ice.CompressionNotSupportedException(); + throw new CompressionNotSupportedException(); } } stream.pos(IceInternal.Protocol.headerSize); @@ -1089,7 +1089,7 @@ namespace Ice } else { - setState(StateClosed, new Ice.CloseConnectionException()); + setState(StateClosed, new CloseConnectionException()); } break; } @@ -1128,7 +1128,7 @@ namespace Ice invokeNum = stream.readInt(); if(invokeNum < 0) { - throw new Ice.NegativeSizeException(); + throw new NegativeSizeException(); } servantManager = _servantManager; adapter = _adapter; @@ -1153,7 +1153,7 @@ namespace Ice _asyncRequests.Remove(requestId); if(outAsync == null) { - throw new Ice.UnknownRequestIdException(); + throw new UnknownRequestIdException(); } } break; @@ -1175,11 +1175,11 @@ namespace Ice IceInternal.TraceUtil.traceHeader("received unknown message\n" + "(invalid, closing connection)", stream, _logger, _traceLevels); - throw new Ice.UnknownMessageException(); + throw new UnknownMessageException(); } } } - catch(Ice.LocalException ex) + catch(LocalException ex) { setState(StateClosed, ex); return; @@ -1242,10 +1242,8 @@ namespace Ice inc = null; } } - catch(Ice.LocalException ex) + catch(LocalException ex) { - Debug.Assert(invokeNum > 0); - lock(this) { setState(StateClosed, ex); @@ -1253,15 +1251,11 @@ namespace Ice } catch(System.Exception ex) { - // - // For other errors, we don't kill the whole - // process, but just print the stack trace and close the - // connection. - // - warning("closing connection", ex); lock(this) { - setState(StateClosed, new Ice.UnknownException()); + UnknownException uex = new UnknownException(); + uex.unknown = ex.ToString(); + setState(StateClosed, uex); } } finally @@ -1270,33 +1264,33 @@ namespace Ice { reclaimIncoming(inc); } - - // - // If invoke() above raised an exception, and therefore - // neither sendResponse() nor sendNoResponse() has been - // called, then we must decrement _dispatchCount here. - // - if(invokeNum > 0) + } + + // + // If invoke() above raised an exception, and therefore + // neither sendResponse() nor sendNoResponse() has been + // called, then we must decrement _dispatchCount here. + // + if(invokeNum > 0) + { + lock(this) { - lock(this) + Debug.Assert(_dispatchCount > 0); + _dispatchCount -= invokeNum; + Debug.Assert(_dispatchCount >= 0); + if(_dispatchCount == 0) { - Debug.Assert(_dispatchCount > 0); - _dispatchCount -= invokeNum; - Debug.Assert(_dispatchCount >= 0); - if(_dispatchCount == 0) - { - Monitor.PulseAll(this); - } + Monitor.PulseAll(this); } } } } - + public override void finished(IceInternal.ThreadPool threadPool) { threadPool.promoteFollower(); - Ice.LocalException exception = null; + LocalException exception = null; Hashtable requests = null; Hashtable asyncRequests = null; @@ -1320,7 +1314,7 @@ namespace Ice { _transceiver.close(); } - catch(Ice.LocalException ex) + catch(LocalException ex) { exception = ex; } @@ -1368,7 +1362,7 @@ namespace Ice } } - public override void exception(Ice.LocalException ex) + public override void exception(LocalException ex) { lock(this) { @@ -1402,7 +1396,7 @@ namespace Ice } internal ConnectionI(IceInternal.Instance instance, IceInternal.Transceiver transceiver, - IceInternal.Endpoint endpoint, Ice.ObjectAdapter adapter) + IceInternal.Endpoint endpoint, ObjectAdapter adapter) : base(instance) { _transceiver = transceiver; @@ -1427,8 +1421,8 @@ namespace Ice if(_adapter != null) { - _threadPool = ((Ice.ObjectAdapterI) _adapter).getThreadPool(); - _servantManager = ((Ice.ObjectAdapterI) _adapter).getServantManager(); + _threadPool = ((ObjectAdapterI) _adapter).getThreadPool(); + _servantManager = ((ObjectAdapterI) _adapter).getServantManager(); } else { @@ -1456,7 +1450,7 @@ namespace Ice private const int StateClosing = 3; private const int StateClosed = 4; - private void setState(int state, Ice.LocalException ex) + private void setState(int state, LocalException ex) { // // If setState() is called with an exception, then only closed @@ -1483,11 +1477,11 @@ namespace Ice // // Don't warn about certain expected exceptions. // - if(!(_exception is Ice.CloseConnectionException || - _exception is Ice.ConnectionTimeoutException || - _exception is Ice.CommunicatorDestroyedException || - _exception is Ice.ObjectAdapterDeactivatedException || - (_exception is Ice.ConnectionLostException && _state == StateClosing))) + if(!(_exception is CloseConnectionException || + _exception is ConnectionTimeoutException || + _exception is CommunicatorDestroyedException || + _exception is ObjectAdapterDeactivatedException || + (_exception is ConnectionLostException && _state == StateClosing))) { warning("connection exception", _exception); } @@ -1590,7 +1584,7 @@ namespace Ice { _transceiver.close(); } - catch(Ice.LocalException) + catch(LocalException) { // Here we ignore any exceptions in close(). } @@ -1618,7 +1612,7 @@ namespace Ice { initiateShutdown(); } - catch(Ice.LocalException ex) + catch(LocalException ex) { setState(StateClosed, ex); } @@ -1742,10 +1736,10 @@ namespace Ice private volatile string _type; private volatile IceInternal.Endpoint _endpoint; - private Ice.ObjectAdapter _adapter; + private ObjectAdapter _adapter; private IceInternal.ServantManager _servantManager; - private volatile Ice.Logger _logger; + private volatile Logger _logger; private volatile IceInternal.TraceLevels _traceLevels; private bool _registeredWithPool; @@ -1760,7 +1754,7 @@ namespace Ice private Hashtable _requests = new Hashtable(); private Hashtable _asyncRequests = new Hashtable(); - private Ice.LocalException _exception; + private LocalException _exception; private IceInternal.BasicStream _batchStream; private bool _batchStreamInUse; diff --git a/cs/src/Ice/Incoming.cs b/cs/src/Ice/Incoming.cs index 1525538e09f..a35165ec408 100755 --- a/cs/src/Ice/Incoming.cs +++ b/cs/src/Ice/Incoming.cs @@ -110,28 +110,6 @@ namespace IceInternal _connection = connection; } - protected internal void __finishInvoke() - { - if(_locator != null && _servant != null) - { - _locator.finished(_current, _servant, _cookie); - } - - // - // Send a response if necessary. If we don't need to send a - // response, we still need to tell the connection that we're - // finished with dispatching. - // - if(_response) - { - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - } - protected internal void __warning(System.Exception ex) { Debug.Assert(_os != null); @@ -158,7 +136,7 @@ namespace IceInternal protected internal BasicStream _os; - private Ice.ConnectionI _connection; + protected Ice.ConnectionI _connection; } sealed public class Incoming : IncomingBase @@ -262,44 +240,54 @@ namespace IceInternal try { - if(servantManager != null) + try { - _servant = servantManager.findServant(_current.id, _current.facet); - - if(_servant == null && _current.id.category.Length > 0) + if(servantManager != null) { - _locator = servantManager.findServantLocator(_current.id.category); - if(_locator != null) + _servant = servantManager.findServant(_current.id, _current.facet); + + if(_servant == null && _current.id.category.Length > 0) + { + _locator = servantManager.findServantLocator(_current.id.category); + if(_locator != null) + { + _servant = _locator.locate(_current, out _cookie); + } + } + + if(_servant == null) { - _servant = _locator.locate(_current, out _cookie); + _locator = servantManager.findServantLocator(""); + if(_locator != null) + { + _servant = _locator.locate(_current, out _cookie); + } } } if(_servant == null) { - _locator = servantManager.findServantLocator(""); - if(_locator != null) + if(servantManager != null && servantManager.hasServant(_current.id)) + { + status = DispatchStatus.DispatchFacetNotExist; + } + else { - _servant = _locator.locate(_current, out _cookie); + status = DispatchStatus.DispatchObjectNotExist; } } + else + { + status = _servant.__dispatch(this, _current); + } } - - if(_servant == null) + finally { - if(servantManager != null && servantManager.hasServant(_current.id)) - { - status = DispatchStatus.DispatchFacetNotExist; - } - else - { - status = DispatchStatus.DispatchObjectNotExist; - } - } - else - { - status = _servant.__dispatch(this, _current); - } + if(_locator != null && _servant != null && status != DispatchStatus.DispatchAsync) + { + _locator.finished(_current, _servant, _cookie.value); + } + } } catch(Ice.RequestFailedException ex) { @@ -361,13 +349,14 @@ namespace IceInternal } _os.writeString(ex.operation); + + _connection.sendResponse(_os, _compress); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + else + { + _connection.sendNoResponse(); + } + return; } catch(Ice.UnknownLocalException ex) @@ -385,13 +374,13 @@ namespace IceInternal _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. _os.writeByte((byte)DispatchStatus.DispatchUnknownLocalException); _os.writeString(ex.unknown); + _connection.sendResponse(_os, _compress); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + else + { + _connection.sendNoResponse(); + } + return; } catch(Ice.UnknownUserException ex) @@ -409,13 +398,13 @@ namespace IceInternal _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. _os.writeByte((byte)DispatchStatus.DispatchUnknownUserException); _os.writeString(ex.unknown); + _connection.sendResponse(_os, _compress); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + else + { + _connection.sendNoResponse(); + } + return; } catch(Ice.UnknownException ex) @@ -433,13 +422,13 @@ namespace IceInternal _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. _os.writeByte((byte)DispatchStatus.DispatchUnknownException); _os.writeString(ex.unknown); + _connection.sendResponse(_os, _compress); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + else + { + _connection.sendNoResponse(); + } + return; } catch(Ice.LocalException ex) @@ -457,13 +446,13 @@ namespace IceInternal _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. _os.writeByte((byte)DispatchStatus.DispatchUnknownLocalException); _os.writeString(ex.ToString()); + _connection.sendResponse(_os, _compress); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + else + { + _connection.sendNoResponse(); + } + return; } @@ -482,13 +471,13 @@ namespace IceInternal _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. _os.writeByte((byte)DispatchStatus.DispatchUnknownUserException); _os.writeString(ex.ToString()); + _connection.sendResponse(_os, _compress); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + else + { + _connection.sendNoResponse(); + } + return; } @@ -507,13 +496,13 @@ namespace IceInternal _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. _os.writeByte((byte) DispatchStatus.DispatchUnknownException); _os.writeString(ex.ToString()); + _connection.sendResponse(_os, _compress); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + else + { + _connection.sendNoResponse(); + } + return; } @@ -533,8 +522,7 @@ namespace IceInternal { // // If this was an asynchronous dispatch, we're done - // here. We do *not* call __finishInvoke(), because - // the call is not finished yet. + // here. // return; } @@ -576,13 +564,13 @@ namespace IceInternal _os.writeByte((byte)status); _os.pos(save); } + + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); } public BasicStream istr() diff --git a/cs/src/Ice/IncomingAsync.cs b/cs/src/Ice/IncomingAsync.cs index 9f4213e311a..f73733e5f5d 100755 --- a/cs/src/Ice/IncomingAsync.cs +++ b/cs/src/Ice/IncomingAsync.cs @@ -18,7 +18,6 @@ namespace IceInternal public IncomingAsync(Incoming inc) : base(inc) { - _finished = false; } ~IncomingAsync() @@ -36,210 +35,267 @@ namespace IceInternal protected internal void __response(bool ok) { - Debug.Assert(!_finished); - _finished = true; - - if(_response) - { - _os.endWriteEncaps(); + try + { + if(_locator != null && _servant != null) + { + _locator.finished(_current, _servant, _cookie.value); + } + + if(_response) + { + _os.endWriteEncaps(); - int save = _os.pos(); - _os.pos(Protocol.headerSize + 4); // Dispatch status position. + int save = _os.pos(); + _os.pos(Protocol.headerSize + 4); // Dispatch status position. - if(ok) - { - _os.writeByte((byte)DispatchStatus.DispatchOK); - } - else - { - _os.writeByte((byte)DispatchStatus.DispatchUserException); - } + if(ok) + { + _os.writeByte((byte)DispatchStatus.DispatchOK); + } + else + { + _os.writeByte((byte)DispatchStatus.DispatchUserException); + } - _os.pos(save); - } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + _os.pos(save); + + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(Ice.LocalException ex) + { + _connection.exception(ex); + } + catch(System.Exception ex) + { + Ice.UnknownException uex = new Ice.UnknownException(); + uex.unknown = ex.ToString(); + _connection.exception(uex); + } } protected internal void __exception(System.Exception exc) { - Debug.Assert(!_finished); - _finished = true; - - try - { - throw exc; - } - catch(Ice.RequestFailedException ex) - { - if(ex.id.name == null) - { - ex.id = _current.id; - } + try + { + if(_locator != null && _servant != null) + { + _locator.finished(_current, _servant, _cookie.value); + } + + try + { + throw exc; + } + catch(Ice.RequestFailedException ex) + { + if(ex.id.name == null) + { + ex.id = _current.id; + } - if(ex.facet == null) - { - ex.facet = _current.facet; - } + if(ex.facet == null) + { + ex.facet = _current.facet; + } - if(ex.operation == null || ex.operation.Length == 0) - { - ex.operation = _current.operation; - } + if(ex.operation == null || ex.operation.Length == 0) + { + ex.operation = _current.operation; + } - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) - { - __warning(ex); - } + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - if(ex is Ice.ObjectNotExistException) - { - _os.writeByte((byte)DispatchStatus.DispatchObjectNotExist); - } - else if(ex is Ice.FacetNotExistException) - { - _os.writeByte((byte)DispatchStatus.DispatchFacetNotExist); - } - else if(ex is Ice.OperationNotExistException) - { - _os.writeByte((byte)DispatchStatus.DispatchOperationNotExist); - } - else - { - Debug.Assert(false); - } - ex.id.__write(_os); + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + if(ex is Ice.ObjectNotExistException) + { + _os.writeByte((byte)DispatchStatus.DispatchObjectNotExist); + } + else if(ex is Ice.FacetNotExistException) + { + _os.writeByte((byte)DispatchStatus.DispatchFacetNotExist); + } + else if(ex is Ice.OperationNotExistException) + { + _os.writeByte((byte)DispatchStatus.DispatchOperationNotExist); + } + else + { + Debug.Assert(false); + } + ex.id.__write(_os); + + // + // For compatibility with the old FacetPath. + // + if(ex.facet == null || ex.facet.Length == 0) + { + _os.writeStringSeq(null); + } + else + { + string[] facetPath = { ex.facet }; + _os.writeStringSeq(facetPath); + } - // - // For compatibility with the old FacetPath. - // - if(ex.facet == null || ex.facet.Length == 0) - { - _os.writeStringSeq(null); - } - else - { - string[] facetPath = { ex.facet }; - _os.writeStringSeq(facetPath); - } + _os.writeString(ex.operation); - _os.writeString(ex.operation); - } - } - catch(Ice.UnknownLocalException ex) - { - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(Ice.UnknownLocalException ex) + { + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus.DispatchUnknownLocalException); - _os.writeString(ex.unknown); - } - } - catch(Ice.UnknownUserException ex) - { - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus.DispatchUnknownLocalException); + _os.writeString(ex.unknown); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(Ice.UnknownUserException ex) + { + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus.DispatchUnknownUserException); - _os.writeString(ex.unknown); - } - } - catch(Ice.UnknownException ex) - { - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus.DispatchUnknownUserException); + _os.writeString(ex.unknown); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(Ice.UnknownException ex) + { + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus.DispatchUnknownException); - _os.writeString(ex.unknown); - } - } - catch(Ice.LocalException ex) - { - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus.DispatchUnknownException); + _os.writeString(ex.unknown); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(Ice.LocalException ex) + { + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus.DispatchUnknownLocalException); - _os.writeString(ex.ToString()); - } - } - catch(Ice.UserException ex) - { - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus.DispatchUnknownLocalException); + _os.writeString(ex.ToString()); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(Ice.UserException ex) + { + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus.DispatchUnknownUserException); - _os.writeString(ex.ToString()); - } - } - catch(System.Exception ex) - { - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus.DispatchUnknownUserException); + _os.writeString(ex.ToString()); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(System.Exception ex) + { + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus.DispatchUnknownException); - _os.writeString(ex.ToString()); - } - } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus.DispatchUnknownException); + _os.writeString(ex.ToString()); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + } + catch(Ice.LocalException ex) + { + _connection.exception(ex); + } + catch(System.Exception ex) + { + Ice.UnknownException uex = new Ice.UnknownException(); + uex.unknown = ex.ToString(); + _connection.exception(uex); + } } protected internal BasicStream __os() { return _os; } - - protected internal bool _finished; } - } namespace Ice @@ -260,23 +316,21 @@ namespace Ice public void ice_response(bool ok, byte[] outParams) { - try - { - __os().writeBlob(outParams); - } - catch(Ice.LocalException ex) - { - __exception(ex); - return; - } - - __response(ok); - } + try + { + __os().writeBlob(outParams); + } + catch(Ice.LocalException ex) + { + __exception(ex); + return; + } + __response(ok); + } public void ice_exception(System.Exception ex) { - __exception(ex); + __exception(ex); } } - } diff --git a/java/CHANGES b/java/CHANGES index 4e59c1a23ec..46df51acc79 100644 --- a/java/CHANGES +++ b/java/CHANGES @@ -1,6 +1,11 @@ Changes since version 1.5.1 --------------------------- +- Fixed a bug with AMD exception handling, where it was possible that + certain exceptions propagate out of ice_response() or + ice_exception(), and therefore such exceptions were not handled + properly. + - Exceptions raised while marshaling data for batch requests resulted in a connection deadlock. This has been fixed. diff --git a/java/src/Ice/Application.java b/java/src/Ice/Application.java index 028250ee33d..d42d1b9177b 100644 --- a/java/src/Ice/Application.java +++ b/java/src/Ice/Application.java @@ -71,7 +71,7 @@ public abstract class Application ex.printStackTrace(); status = 1; } - catch(Exception ex) + catch(java.lang.Exception ex) { System.err.println(_appName + ": unknown exception"); ex.printStackTrace(); @@ -90,7 +90,7 @@ public abstract class Application ex.printStackTrace(); status = 1; } - catch(Exception ex) + catch(java.lang.Exception ex) { System.err.println(_appName + ": unknown exception"); ex.printStackTrace(); diff --git a/java/src/Ice/ConnectionI.java b/java/src/Ice/ConnectionI.java index 5d985429f03..1cb6f68a38b 100644 --- a/java/src/Ice/ConnectionI.java +++ b/java/src/Ice/ConnectionI.java @@ -1207,32 +1207,41 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne } catch(LocalException ex) { - assert(invokeNum > 0); - synchronized(this) { setState(StateClosed, ex); } } - catch(AssertionError ex) + catch(java.lang.AssertionError ex) // Upon assertion, we print the stack trace. { - assert(invokeNum > 0); - - // - // Java only: Upon an assertion, we don't kill the whole - // process, but just print the stack trace and close the - // connection. - // synchronized(this) { + UnknownException uex = new UnknownException(); + //uex.unknown = ex.toString(); java.io.StringWriter sw = new java.io.StringWriter(); java.io.PrintWriter pw = new java.io.PrintWriter(sw); ex.printStackTrace(pw); pw.flush(); - UnknownException exc = new UnknownException(); - exc.unknown = sw.toString(); - _logger.error(exc.unknown); - setState(StateClosed, exc); + uex.unknown = sw.toString(); + if(ex instanceof java.lang.AssertionError) + { + _logger.error(uex.unknown); + } + setState(StateClosed, uex); + } + } + catch(java.lang.Exception ex) + { + synchronized(this) + { + UnknownException uex = new UnknownException(); + //uex.unknown = ex.toString(); + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + ex.printStackTrace(pw); + pw.flush(); + uex.unknown = sw.toString(); + setState(StateClosed, uex); } } finally @@ -1241,23 +1250,23 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne { reclaimIncoming(in); } - - // - // If invoke() above raised an exception, and therefore - // neither sendResponse() nor sendNoResponse() has been - // called, then we must decrement _dispatchCount here. - // - if(invokeNum > 0) + } + + // + // If invoke() above raised an exception, and therefore + // neither sendResponse() nor sendNoResponse() has been + // called, then we must decrement _dispatchCount here. + // + if(invokeNum > 0) + { + synchronized(this) { - synchronized(this) + assert(_dispatchCount > 0); + _dispatchCount -= invokeNum; + assert(_dispatchCount >= 0); + if(_dispatchCount == 0) { - assert(_dispatchCount > 0); - _dispatchCount -= invokeNum; - assert(_dispatchCount >= 0); - if(_dispatchCount == 0) - { - notifyAll(); - } + notifyAll(); } } } diff --git a/java/src/Ice/PluginManagerI.java b/java/src/Ice/PluginManagerI.java index 5956990c479..792e79d4105 100644 --- a/java/src/Ice/PluginManagerI.java +++ b/java/src/Ice/PluginManagerI.java @@ -186,7 +186,7 @@ public final class PluginManagerI extends LocalObjectImpl implements PluginManag { plugin = factory.create(_communicator, name, args); } - catch(Exception ex) + catch(java.lang.Exception ex) { PluginInitializationException e = new PluginInitializationException(); e.reason = "exception in factory " + className; diff --git a/java/src/Ice/_AMD_Object_ice_invoke.java b/java/src/Ice/_AMD_Object_ice_invoke.java index 36e72b05f67..946048bf540 100644 --- a/java/src/Ice/_AMD_Object_ice_invoke.java +++ b/java/src/Ice/_AMD_Object_ice_invoke.java @@ -29,7 +29,6 @@ final class _AMD_Object_ice_invoke extends IceInternal.IncomingAsync implements __exception(ex); return; } - __response(ok); } diff --git a/java/src/IceBox/ServiceManagerI.java b/java/src/IceBox/ServiceManagerI.java index 4c407199912..c75414f2169 100644 --- a/java/src/IceBox/ServiceManagerI.java +++ b/java/src/IceBox/ServiceManagerI.java @@ -167,7 +167,7 @@ public final class ServiceManagerI extends _ServiceManagerDisp stopAll(); return 1; } - catch(Exception ex) + catch(java.lang.Exception ex) { java.io.StringWriter sw = new java.io.StringWriter(); java.io.PrintWriter pw = new java.io.PrintWriter(sw); @@ -327,7 +327,7 @@ public final class ServiceManagerI extends _ServiceManagerDisp { throw ex; } - catch(Exception ex) + catch(java.lang.Exception ex) { FailureException e = new FailureException(); e.reason = "ServiceManager: exception while starting service " + service + ": " + ex; @@ -353,7 +353,7 @@ public final class ServiceManagerI extends _ServiceManagerDisp { info.service.stop(); } - catch(Exception e) + catch(java.lang.Exception e) { java.io.StringWriter sw = new java.io.StringWriter(); java.io.PrintWriter pw = new java.io.PrintWriter(sw); @@ -389,7 +389,7 @@ public final class ServiceManagerI extends _ServiceManagerDisp // the communicator for its own reasons. // } - catch(Exception e) + catch(java.lang.Exception e) { java.io.StringWriter sw = new java.io.StringWriter(); java.io.PrintWriter pw = new java.io.PrintWriter(sw); @@ -405,7 +405,7 @@ public final class ServiceManagerI extends _ServiceManagerDisp { info.communicator.destroy(); } - catch(Exception e) + catch(java.lang.Exception e) { java.io.StringWriter sw = new java.io.StringWriter(); java.io.PrintWriter pw = new java.io.PrintWriter(sw); diff --git a/java/src/IceInternal/BasicStream.java b/java/src/IceInternal/BasicStream.java index 643a7f9cf9e..2eb053a5cc5 100644 --- a/java/src/IceInternal/BasicStream.java +++ b/java/src/IceInternal/BasicStream.java @@ -1505,7 +1505,7 @@ public class BasicStream { obj.ice_postUnmarshal(); } - catch(Exception ex) + catch(java.lang.Exception ex) { java.io.StringWriter sw = new java.io.StringWriter(); java.io.PrintWriter pw = new java.io.PrintWriter(sw); @@ -1534,7 +1534,7 @@ public class BasicStream { v.ice_preMarshal(); } - catch(Exception ex) + catch(java.lang.Exception ex) { java.io.StringWriter sw = new java.io.StringWriter(); java.io.PrintWriter pw = new java.io.PrintWriter(sw); @@ -1680,7 +1680,7 @@ public class BasicStream { return (Ice.Object)_class.newInstance(); } - catch(Exception ex) + catch(java.lang.Exception ex) { Ice.SyscallException e = new Ice.SyscallException(); e.initCause(ex); @@ -1763,7 +1763,7 @@ public class BasicStream { throw ex; } - catch(Exception ex) + catch(java.lang.Exception ex) { Ice.SyscallException e = new Ice.SyscallException(); e.initCause(ex); diff --git a/java/src/IceInternal/ConnectionMonitor.java b/java/src/IceInternal/ConnectionMonitor.java index 593cefc5ebf..6c6fc1efd5b 100644 --- a/java/src/IceInternal/ConnectionMonitor.java +++ b/java/src/IceInternal/ConnectionMonitor.java @@ -140,7 +140,7 @@ public final class ConnectionMonitor extends Thread _instance.logger().error(s); } } - catch(Exception ex) + catch(java.lang.Exception ex) { synchronized(this) { diff --git a/java/src/IceInternal/Incoming.java b/java/src/IceInternal/Incoming.java index f447e41a76e..ffbc91b4ad0 100644 --- a/java/src/IceInternal/Incoming.java +++ b/java/src/IceInternal/Incoming.java @@ -103,7 +103,8 @@ final public class Incoming extends IncomingBase _os.startWriteEncaps(); } - DispatchStatus status; + // Initialize status to some value, to keep the compiler happy. + DispatchStatus status = DispatchStatus.DispatchOK; // // Don't put the code above into the try block below. Exceptions @@ -113,49 +114,59 @@ final public class Incoming extends IncomingBase try { - if(servantManager != null) + try { - _servant = servantManager.findServant(_current.id, _current.facet); - - if(_servant == null && _current.id.category.length() > 0) + if(servantManager != null) { - _locator = servantManager.findServantLocator(_current.id.category); - if(_locator != null) + _servant = servantManager.findServant(_current.id, _current.facet); + + if(_servant == null && _current.id.category.length() > 0) + { + _locator = servantManager.findServantLocator(_current.id.category); + if(_locator != null) + { + _servant = _locator.locate(_current, _cookie); + } + } + + if(_servant == null) { - _servant = _locator.locate(_current, _cookie); + _locator = servantManager.findServantLocator(""); + if(_locator != null) + { + _servant = _locator.locate(_current, _cookie); + } } } if(_servant == null) { - _locator = servantManager.findServantLocator(""); - if(_locator != null) + if(servantManager != null && servantManager.hasServant(_current.id)) + { + status = DispatchStatus.DispatchFacetNotExist; + } + else { - _servant = _locator.locate(_current, _cookie); + status = DispatchStatus.DispatchObjectNotExist; } } + else + { + status = _servant.__dispatch(this, _current); + } } - - if(_servant == null) - { - if(servantManager != null && servantManager.hasServant(_current.id)) - { - status = DispatchStatus.DispatchFacetNotExist; - } - else - { - status = DispatchStatus.DispatchObjectNotExist; - } - } - else - { - status = _servant.__dispatch(this, _current); - } - } - catch(Ice.RequestFailedException ex) - { + finally + { + if(_locator != null && _servant != null && status != DispatchStatus.DispatchAsync) + { + _locator.finished(_current, _servant, _cookie.value); + } + } + } + catch(Ice.RequestFailedException ex) + { _is.endReadEncaps(); - + if(ex.id == null) { ex.id = _current.id; @@ -212,13 +223,14 @@ final public class Incoming extends IncomingBase } _os.writeString(ex.operation); - } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + return; } catch(Ice.UnknownLocalException ex) @@ -236,13 +248,13 @@ final public class Incoming extends IncomingBase _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException); _os.writeString(ex.unknown); - } + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); return; } catch(Ice.UnknownUserException ex) @@ -260,13 +272,13 @@ final public class Incoming extends IncomingBase _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. _os.writeByte((byte)DispatchStatus._DispatchUnknownUserException); _os.writeString(ex.unknown); - } + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); return; } catch(Ice.UnknownException ex) @@ -284,13 +296,13 @@ final public class Incoming extends IncomingBase _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. _os.writeByte((byte)DispatchStatus._DispatchUnknownException); _os.writeString(ex.unknown); - } + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); return; } catch(Ice.LocalException ex) @@ -307,18 +319,19 @@ final public class Incoming extends IncomingBase _os.endWriteEncaps(); _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException); + //_os.writeString(ex.toString()); java.io.StringWriter sw = new java.io.StringWriter(); java.io.PrintWriter pw = new java.io.PrintWriter(sw); ex.printStackTrace(pw); pw.flush(); _os.writeString(sw.toString()); - } + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); return; } /* Not possible in Java - UserExceptions are checked exceptions @@ -327,7 +340,7 @@ final public class Incoming extends IncomingBase // ... } */ - catch(Exception ex) + catch(java.lang.Exception ex) { _is.endReadEncaps(); @@ -341,18 +354,19 @@ final public class Incoming extends IncomingBase _os.endWriteEncaps(); _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. _os.writeByte((byte)DispatchStatus._DispatchUnknownException); + //_os.writeString(ex.toString()); java.io.StringWriter sw = new java.io.StringWriter(); java.io.PrintWriter pw = new java.io.PrintWriter(sw); ex.printStackTrace(pw); pw.flush(); _os.writeString(sw.toString()); - } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + return; } @@ -371,9 +385,7 @@ final public class Incoming extends IncomingBase if(status == DispatchStatus.DispatchAsync) { // - // If this was an asynchronous dispatch, we're done - // here. We do *not* call __finishInvoke(), because - // the call is not finished yet. + // If this was an asynchronous dispatch, we're done here. // return; } @@ -415,13 +427,13 @@ final public class Incoming extends IncomingBase _os.writeByte((byte)status.value()); _os.pos(save); } - } - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } } public BasicStream diff --git a/java/src/IceInternal/IncomingAsync.java b/java/src/IceInternal/IncomingAsync.java index 20e6fef10fa..3770bbc1a79 100644 --- a/java/src/IceInternal/IncomingAsync.java +++ b/java/src/IceInternal/IncomingAsync.java @@ -15,7 +15,6 @@ public class IncomingAsync extends IncomingBase IncomingAsync(Incoming in) // Adopts the argument. It must not be used afterwards. { super(in); - _finished = false; } protected void @@ -35,216 +34,286 @@ public class IncomingAsync extends IncomingBase final protected void __response(boolean ok) { - assert(!_finished); - _finished = true; - - if(_response) + try { - _os.endWriteEncaps(); - - int save = _os.pos(); - _os.pos(Protocol.headerSize + 4); // Dispatch status position. + if(_locator != null && _servant != null) + { + _locator.finished(_current, _servant, _cookie.value); + } - if(ok) + if(_response) { - _os.writeByte((byte)DispatchStatus._DispatchOK); + _os.endWriteEncaps(); + + int save = _os.pos(); + _os.pos(Protocol.headerSize + 4); // Dispatch status position. + + if(ok) + { + _os.writeByte((byte)DispatchStatus._DispatchOK); + } + else + { + _os.writeByte((byte)DispatchStatus._DispatchUserException); + } + + _os.pos(save); + + _connection.sendResponse(_os, _compress); } else { - _os.writeByte((byte)DispatchStatus._DispatchUserException); + _connection.sendNoResponse(); } - - _os.pos(save); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + catch(Ice.LocalException ex) + { + _connection.exception(ex); + } + catch(java.lang.Exception ex) + { + Ice.UnknownException uex = new Ice.UnknownException(); + //uex.unknown = ex.toString(); + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + ex.printStackTrace(pw); + pw.flush(); + uex.unknown = sw.toString(); + _connection.exception(uex); + } } final protected void - __exception(Exception exc) + __exception(java.lang.Exception exc) { - assert(!_finished); - _finished = true; - try { - throw exc; - } - catch(Ice.RequestFailedException ex) - { - if(ex.id == null) + if(_locator != null && _servant != null) { - ex.id = _current.id; - } - - if(ex.facet == null) - { - ex.facet = _current.facet; - } - - if(ex.operation == null || ex.operation.length() == 0) - { - ex.operation = _current.operation; + _locator.finished(_current, _servant, _cookie.value); } - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) + try { - __warning(ex); + throw exc; } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - if(ex instanceof Ice.ObjectNotExistException) + catch(Ice.RequestFailedException ex) + { + if(ex.id == null) { - _os.writeByte((byte)DispatchStatus._DispatchObjectNotExist); + ex.id = _current.id; } - else if(ex instanceof Ice.FacetNotExistException) + + if(ex.facet == null) { - _os.writeByte((byte)DispatchStatus._DispatchFacetNotExist); + ex.facet = _current.facet; } - else if(ex instanceof Ice.OperationNotExistException) + + if(ex.operation == null || ex.operation.length() == 0) { - _os.writeByte((byte)DispatchStatus._DispatchOperationNotExist); + ex.operation = _current.operation; } - else + + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) { - assert(false); + __warning(ex); } - ex.id.__write(_os); - // - // For compatibility with the old FacetPath. - // - if(ex.facet == null || ex.facet.length() == 0) - { - _os.writeStringSeq(null); - } - else - { - String[] facetPath = { ex.facet }; - _os.writeStringSeq(facetPath); - } + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + if(ex instanceof Ice.ObjectNotExistException) + { + _os.writeByte((byte)DispatchStatus._DispatchObjectNotExist); + } + else if(ex instanceof Ice.FacetNotExistException) + { + _os.writeByte((byte)DispatchStatus._DispatchFacetNotExist); + } + else if(ex instanceof Ice.OperationNotExistException) + { + _os.writeByte((byte)DispatchStatus._DispatchOperationNotExist); + } + else + { + assert(false); + } + ex.id.__write(_os); - _os.writeString(ex.operation); - } - } - catch(Ice.UnknownLocalException ex) - { - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } + // + // For compatibility with the old FacetPath. + // + if(ex.facet == null || ex.facet.length() == 0) + { + _os.writeStringSeq(null); + } + else + { + String[] facetPath = { ex.facet }; + _os.writeStringSeq(facetPath); + } - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException); - _os.writeString(ex.unknown); - } - } - catch(Ice.UnknownUserException ex) - { - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } + _os.writeString(ex.operation); - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownUserException); - _os.writeString(ex.unknown); - } - } - catch(Ice.UnknownException ex) - { - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownException); - _os.writeString(ex.unknown); - } - } - catch(Ice.LocalException ex) - { - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + catch(Ice.UnknownLocalException ex) { - __warning(ex); + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException); + _os.writeString(ex.unknown); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } } + catch(Ice.UnknownUserException ex) + { + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException); -// _os.writeString(ex.toString()); - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - _os.writeString(sw.toString()); - } - } - catch(Ice.UserException ex) - { - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus._DispatchUnknownUserException); + _os.writeString(ex.unknown); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(Ice.UnknownException ex) { - __warning(ex); + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus._DispatchUnknownException); + _os.writeString(ex.unknown); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } } + catch(Ice.LocalException ex) + { + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownUserException); -// _os.writeString(ex.toString()); - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - _os.writeString(sw.toString()); - } - } - catch(Exception ex) - { - if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException); + //_os.writeString(ex.toString()); + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + ex.printStackTrace(pw); + pw.flush(); + _os.writeString(sw.toString()); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(Ice.UserException ex) { - __warning(ex); + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus._DispatchUnknownUserException); + //_os.writeString(ex.toString()); + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + ex.printStackTrace(pw); + pw.flush(); + _os.writeString(sw.toString()); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } } + catch(java.lang.Exception ex) + { + if(_os.instance().properties().getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownException); -// _os.writeString(ex.toString()); - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - _os.writeString(sw.toString()); - } + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus._DispatchUnknownException); + //_os.writeString(ex.toString()); + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + ex.printStackTrace(pw); + pw.flush(); + _os.writeString(sw.toString()); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + } + catch(Ice.LocalException ex) + { + _connection.exception(ex); + } + catch(java.lang.Exception ex) + { + Ice.UnknownException uex = new Ice.UnknownException(); + //uex.unknown = ex.toString(); + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + ex.printStackTrace(pw); + pw.flush(); + uex.unknown = sw.toString(); + _connection.exception(uex); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); } final protected BasicStream @@ -252,6 +321,4 @@ public class IncomingAsync extends IncomingBase { return _os; } - - protected boolean _finished; } diff --git a/java/src/IceInternal/IncomingBase.java b/java/src/IceInternal/IncomingBase.java index 73d5373bc9f..5356a1f7706 100644 --- a/java/src/IceInternal/IncomingBase.java +++ b/java/src/IceInternal/IncomingBase.java @@ -116,30 +116,7 @@ public class IncomingBase } final protected void - __finishInvoke() - { - if(_locator != null && _servant != null) - { - _locator.finished(_current, _servant, _cookie.value); - } - - // - // Send a response if necessary. If we don't need to send a - // response, we still need to tell the connection that we're - // finished with dispatching. - // - if(_response) - { - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - } - - final protected void - __warning(Exception ex) + __warning(java.lang.Exception ex) { assert(_os != null); @@ -167,5 +144,5 @@ public class IncomingBase protected BasicStream _os; - private Ice.ConnectionI _connection; + protected Ice.ConnectionI _connection; } diff --git a/java/src/IceInternal/Instance.java b/java/src/IceInternal/Instance.java index c5b3ba82950..6fb99599217 100644 --- a/java/src/IceInternal/Instance.java +++ b/java/src/IceInternal/Instance.java @@ -596,7 +596,7 @@ public class Instance { Class.forName(className); } - catch(Exception ex) + catch(java.lang.Exception ex) { _logger.warning("unable to validate package: " + key + "=" + pkg); } diff --git a/java/src/IceInternal/OutgoingAsync.java b/java/src/IceInternal/OutgoingAsync.java index 98ccd3cfa77..30718ec1ecb 100644 --- a/java/src/IceInternal/OutgoingAsync.java +++ b/java/src/IceInternal/OutgoingAsync.java @@ -157,7 +157,7 @@ public abstract class OutgoingAsync { __response(status == DispatchStatus._DispatchOK); } - catch(Exception ex) + catch(java.lang.Exception ex) { warning(ex); } @@ -225,7 +225,7 @@ public abstract class OutgoingAsync { ice_exception(exc); } - catch(Exception ex) + catch(java.lang.Exception ex) { warning(ex); } @@ -413,7 +413,7 @@ public abstract class OutgoingAsync protected abstract void __response(boolean ok); private final void - warning(Exception ex) + warning(java.lang.Exception ex) { if(_reference != null) // Don't print anything if cleanup() was already called. { diff --git a/java/src/IceInternal/ServantManager.java b/java/src/IceInternal/ServantManager.java index cd7843e81e6..f7343a40da1 100644 --- a/java/src/IceInternal/ServantManager.java +++ b/java/src/IceInternal/ServantManager.java @@ -214,7 +214,7 @@ public final class ServantManager { locator.deactivate((String)e.getKey()); } - catch(Exception ex) + catch(java.lang.Exception ex) { java.io.StringWriter sw = new java.io.StringWriter(); java.io.PrintWriter pw = new java.io.PrintWriter(sw); diff --git a/java/src/IceInternal/ThreadPool.java b/java/src/IceInternal/ThreadPool.java index b9408d57c52..f916ff256f5 100644 --- a/java/src/IceInternal/ThreadPool.java +++ b/java/src/IceInternal/ThreadPool.java @@ -1116,7 +1116,7 @@ public final class ThreadPool _instance.logger().error(s); promote = true; } - catch(Exception ex) + catch(java.lang.Exception ex) { java.io.StringWriter sw = new java.io.StringWriter(); java.io.PrintWriter pw = new java.io.PrintWriter(sw); |