Skip to content

Commit 2e4e221

Browse files
authored
Fix crash when running ORT under low integrity process like Edge where ETW registration can fail (microsoft#22699)
### Description Make ETW provider registration non-fatal and not throw an exception Needs to work under build with exceptions enabled & --disable_exceptions ### Motivation and Context ORT should not crash Addresses microsoft#22475. Private tested by filer of that issue
1 parent d419df4 commit 2e4e221

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

onnxruntime/core/platform/windows/logging/etw_sink.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ void EtwRegistrationManager::LazyInitialize() {
158158
initialization_status_ = InitializationStatus::Initializing;
159159
etw_status_ = ::TraceLoggingRegisterEx(etw_provider_handle, ORT_TL_EtwEnableCallback, nullptr);
160160
if (FAILED(etw_status_)) {
161+
// Registration can fail when running under Low Integrity process, and should be non-fatal
161162
initialization_status_ = InitializationStatus::Failed;
162-
ORT_THROW("ETW registration failed. Logging will be broken: " + std::to_string(etw_status_));
163+
LOGS_DEFAULT(WARNING) << "Error in ETW registration: " << std::to_string(etw_status_);
163164
}
164165
initialization_status_ = InitializationStatus::Initialized;
165166
}
@@ -176,7 +177,9 @@ void EtwRegistrationManager::InvokeCallbacks(LPCGUID SourceId, ULONG IsEnabled,
176177

177178
std::lock_guard<std::mutex> lock(callbacks_mutex_);
178179
for (const auto& callback : callbacks_) {
179-
(*callback)(SourceId, IsEnabled, Level, MatchAnyKeyword, MatchAllKeyword, FilterData, CallbackContext);
180+
if (callback != nullptr) {
181+
(*callback)(SourceId, IsEnabled, Level, MatchAnyKeyword, MatchAllKeyword, FilterData, CallbackContext);
182+
}
180183
}
181184
}
182185

onnxruntime/core/session/inference_session.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,12 @@ InferenceSession::~InferenceSession() {
735735
// Unregister the session and ETW callbacks
736736
#ifdef _WIN32
737737
std::lock_guard<std::mutex> lock(active_sessions_mutex_);
738-
WindowsTelemetry::UnregisterInternalCallback(callback_ML_ORT_provider_);
739-
logging::EtwRegistrationManager::Instance().UnregisterInternalCallback(callback_ETWSink_provider_);
738+
if (callback_ML_ORT_provider_ != nullptr) {
739+
WindowsTelemetry::UnregisterInternalCallback(callback_ML_ORT_provider_);
740+
}
741+
if (callback_ETWSink_provider_ != nullptr) {
742+
logging::EtwRegistrationManager::Instance().UnregisterInternalCallback(callback_ETWSink_provider_);
743+
}
740744
#endif
741745
active_sessions_.erase(session_id_);
742746

0 commit comments

Comments
 (0)