Skip to content

[ETW] Fix infinite loop in ETWProvider::close#3827

Merged
marcalff merged 3 commits intoopen-telemetry:mainfrom
ThomsonTan:fix_etw_loop
Jan 23, 2026
Merged

[ETW] Fix infinite loop in ETWProvider::close#3827
marcalff merged 3 commits intoopen-telemetry:mainfrom
ThomsonTan:fix_etw_loop

Conversation

@ThomsonTan
Copy link
Contributor

@ThomsonTan ThomsonTan commented Jan 23, 2026

Fixes #3815

Changes

Please provide a brief description of the changes here.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical infinite loop bug in the ETWProvider::close() method identified in issue #3815. The bug occurred when closing a provider handle that wasn't the first entry in the provider map, causing the iterator to never advance and the while loop to hang indefinitely. Additionally, the fix adds protection against refCount underflow when close is called too many times on the same handle.

Changes:

  • Fixed infinite loop by adding missing iterator increment (++it) in the while loop
  • Added refCount underflow protection to prevent negative refCount values
  • Added unit test to verify the infinite loop fix

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
exporters/etw/include/opentelemetry/exporters/etw/etw_provider.h Fixed missing iterator increment and added refCount underflow check in close() method
exporters/etw/test/etw_provider_test.cc Added test case to verify closing multiple providers doesn't cause infinite loop

Comment on lines +74 to +75
etw.close(handle2);
etw.close(handle1);
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should include assertions to verify that the close operations succeeded. Currently, the test only verifies that it doesn't hang, but doesn't check if the operations completed successfully. Consider adding assertions to check the return values and provider registration status.

Copilot uses AI. Check for mistakes.
Comment on lines +64 to +76
TEST(ETWProvider, CheckCloseInfiniteLoop)
{
std::string providerName1 = "Provider1";
std::string providerName2 = "Provider2";

static ETWProvider etw;
auto handle1 = etw.open(providerName1.c_str());
auto handle2 = etw.open(providerName2.c_str());

// This should not hang
etw.close(handle2);
etw.close(handle1);
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test doesn't cover the refCount underflow scenario mentioned in the issue. The fix added a check at lines 213-216 to prevent underflow when close is called too many times on the same handle, but this behavior is not tested. Consider adding a test case that calls close multiple times on the same handle and verifies it returns STATUS_ERROR on subsequent calls.

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.96%. Comparing base (25b9adc) to head (525198c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3827      +/-   ##
==========================================
+ Coverage   89.95%   89.96%   +0.02%     
==========================================
  Files         225      225              
  Lines        7170     7170              
==========================================
+ Hits         6449     6450       +1     
+ Misses        721      720       -1     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marcalff marcalff merged commit 356fc9e into open-telemetry:main Jan 23, 2026
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ETW Exporter: infinite while loop in ETWProvider::close()

4 participants