Skip to content

Conversation

pentp
Copy link
Contributor

@pentp pentp commented Sep 19, 2025

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 in EventSource handling of listeners - if there are multiple listeners and only some of them are enabled, then events with eventId = -1 are still sent to all listeners regardless.

Microsoft Reviewers: Open in CodeFlow

@Copilot Copilot AI review requested due to automatic review settings September 19, 2025 12:24
@pentp pentp requested a review from a team as a code owner September 19, 2025 12:24
Copy link
Contributor

@Copilot 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 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.

@evgenyfedorov2
Copy link
Member

duplicate with #6821 ?

@pentp
Copy link
Contributor Author

pentp commented Sep 19, 2025

duplicate with #6821 ?

It has a different unit test that covers the actual issue where EventSource triggers OnEventWritten for disabled listeners.

@dariusclay
Copy link
Member

Same fix, more tests. Slight formatting differences -- these PRs should stack.

This was referenced Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants