-
Notifications
You must be signed in to change notification settings - Fork 839
Fix KeyNotFoundException
in HttpRequestLatencyListener.OnEventWritten
#6823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 KeyNotFoundException
in HttpRequestLatencyListener.OnEventWritten
by adding proper null checking before accessing the event source map. The issue occurs when EventSource
sends events with eventId = -1
to all listeners regardless of whether they enabled that particular event source.
- Fixed potential
KeyNotFoundException
by adding safe dictionary access - Enhanced test coverage to verify the bug scenario with multiple event listeners
- Updated test infrastructure to enable better error detection
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
HttpRequestLatencyListener.cs | Fixed dictionary access to prevent KeyNotFoundException |
HttpRequestLatencyListenerTest.cs | Added test case reproducing the multi-listener scenario |
HttpMockProvider.cs | Updated MockEventSource to throw on event write errors for better test reliability |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...crosoft.Extensions.Http.Diagnostics.Tests/Latency/Internal/HttpRequestLatencyListenerTest.cs
Show resolved
Hide resolved
duplicate with #6821 ? |
It has a different unit test that covers the actual issue where |
Same fix, more tests. Slight formatting differences -- these PRs should stack. |
This is a workaround for a reported issue with
HttpRequestLatencyListener
where it throws a lot of exceptions under certain circumstances. It appears there's a bug inEventSource
handling of listeners - if there are multiple listeners and only some of them are enabled, then events witheventId = -1
are still sent to all listeners regardless.Microsoft Reviewers: Open in CodeFlow