Skip to content

Commit

Permalink
Log warning on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Nov 11, 2024
1 parent 26f8a84 commit c52e699
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions cpp/src/Ice/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ Ice::Exception::ice_enableStackTraceCollection()
if (!SymRefreshModuleList(process))
{
// TODO: SymRefreshModuleList occasionally fails with error code 3221225476; we retry once in this case.
// Note that calling GetLastError() does not reset the last error.
if (GetLastError() != 3221225476 || !SymRefreshModuleList(process))
{
throw std::runtime_error{
Expand Down
27 changes: 18 additions & 9 deletions cpp/src/Ice/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,27 @@ namespace
}
}

inline bool printStackTraces(const PropertiesPtr& properties)
void checkPrintStackTraces(const InitializationData& initData)
{
#ifdef NDEBUG
// Release build
return properties->getIcePropertyAsInt("Ice.PrintStackTraces") > 0;
if (initData.properties->getIcePropertyAsInt("Ice.PrintStackTraces") > 0)
#else
// Debug build
return properties->getPropertyAsIntWithDefault("Ice.PrintStackTraces", 1);
if (initData.properties->getPropertyAsIntWithDefault("Ice.PrintStackTraces", 1))
#endif
{
try
{
Exception::ice_enableStackTraceCollection();
}
catch (const std::exception& ex)
{
Warning out(initData.logger);
out << "Cannot enable stack trace collection:\n" << ex;
out << "\nYou can turn off this warning by setting Ice.PrintStackTraces=0";
}
}
}

class Init
Expand Down Expand Up @@ -1060,10 +1072,7 @@ IceInternal::Instance::initialize(const Ice::CommunicatorPtr& communicator)
assert(_initData.logger);

// This affects the entire process.
if (printStackTraces(_initData.properties))
{
Exception::ice_enableStackTraceCollection();
}
checkPrintStackTraces(_initData);

const_cast<TraceLevelsPtr&>(_traceLevels) = make_shared<TraceLevels>(_initData.properties);

Expand Down Expand Up @@ -1344,9 +1353,9 @@ IceInternal::Instance::finishSetup(int& argc, const char* argv[], const Ice::Com
// On Windows, if we loaded any plugin and stack trace collection is enabled, we need to call
// ice_enableStackTraceCollection() again to refresh the module list. This refresh is fairly slow so we make it only
// when necessary. Extra calls to ice_enableStackTraceCollection() are no-op on other platforms.
if (libraryLoaded && printStackTraces(_initData.properties))
if (libraryLoaded)
{
Exception::ice_enableStackTraceCollection();
checkPrintStackTraces(_initData);
}

//
Expand Down
11 changes: 10 additions & 1 deletion cpp/src/IceBox/ServiceManagerI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,16 @@ IceBox::ServiceManagerI::start()
// Refresh module list after loading dynamic libraries if stack trace collection is enabled.
if (printStackTraces(_communicator->getProperties()))
{
Exception::ice_enableStackTraceCollection();
try
{
Exception::ice_enableStackTraceCollection();
}
catch (const std::exception& ex)
{
Warning out(_communicator->getLogger());
out << "Cannot enable/refresh stack trace collection:\n" << ex;
out << "\nYou can turn off this warning by setting Ice.PrintStackTraces=0";
}
}

//
Expand Down

0 comments on commit c52e699

Please sign in to comment.