Skip to content

Commit 1ab162f

Browse files
Fix ETW Sink Initialize unproperly locking (microsoft#21226)
### Description ETW trace logger is fakely registered as initialized_ is marked as true before the registration is done, causing crashing issue for Lenovo camera application. [Bug 42610244](https://microsoft.visualstudio.com/OS/_workitems/edit/42610244): [Watson Failure] caused by SVCHOSTGROUP_Camera_INVALID_POINTER_READ_c0000005_onnxruntime.dll!onnxruntime::logging::Logger::Log
1 parent d1c19e7 commit 1ab162f

File tree

2 files changed

+3
-23
lines changed

2 files changed

+3
-23
lines changed

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ ULONGLONG EtwRegistrationManager::Keyword() const {
9898
return keyword_;
9999
}
100100

101-
HRESULT EtwRegistrationManager::Status() const {
102-
return etw_status_;
103-
}
104-
105101
void EtwRegistrationManager::RegisterInternalCallback(const EtwInternalCallback& callback) {
106102
std::lock_guard<OrtMutex> lock(callbacks_mutex_);
107103
callbacks_.push_back(&callback);
@@ -144,15 +140,9 @@ EtwRegistrationManager::EtwRegistrationManager() {
144140
}
145141

146142
void EtwRegistrationManager::LazyInitialize() {
147-
if (!initialized_) {
148-
std::lock_guard<OrtMutex> lock(init_mutex_);
149-
if (!initialized_) { // Double-check locking pattern
150-
initialized_ = true;
151-
etw_status_ = ::TraceLoggingRegisterEx(etw_provider_handle, ORT_TL_EtwEnableCallback, nullptr);
152-
if (FAILED(etw_status_)) {
153-
ORT_THROW("ETW registration failed. Logging will be broken: " + std::to_string(etw_status_));
154-
}
155-
}
143+
static HRESULT etw_status = ::TraceLoggingRegisterEx(etw_provider_handle, ORT_TL_EtwEnableCallback, nullptr);
144+
if (FAILED(etw_status)) {
145+
ORT_THROW("ETW registration failed. Logging will be broken: " + std::to_string(etw_status));
156146
}
157147
}
158148

@@ -171,12 +161,6 @@ void EtwSink::SendImpl(const Timestamp& timestamp, const std::string& logger_id,
171161
// register on first usage
172162
static EtwRegistrationManager& etw_manager = EtwRegistrationManager::Instance();
173163

174-
// do something (not that meaningful) with etw_manager so it doesn't get optimized out
175-
// as we want an instance around to do the unregister
176-
if (FAILED(etw_manager.Status())) {
177-
return;
178-
}
179-
180164
// TODO: Validate if this filtering makes sense.
181165
if (message.DataType() == DataType::USER) {
182166
return;

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ class EtwRegistrationManager {
6666
// Get the current keyword
6767
uint64_t Keyword() const;
6868

69-
// Get the ETW registration status
70-
HRESULT Status() const;
71-
7269
void RegisterInternalCallback(const EtwInternalCallback& callback);
7370

7471
void UnregisterInternalCallback(const EtwInternalCallback& callback);
@@ -100,7 +97,6 @@ class EtwRegistrationManager {
10097
bool is_enabled_;
10198
UCHAR level_;
10299
ULONGLONG keyword_;
103-
HRESULT etw_status_;
104100
};
105101

106102
} // namespace logging

0 commit comments

Comments
 (0)