Skip to content

fix: handle duplicate keys in logger state to prevent ArgumentException #961

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

hjgraca
Copy link
Contributor

@hjgraca hjgraca commented Aug 19, 2025

Please provide the issue number

Issue number: #956

Summary

Changes

Fixes issue where requests with duplicate headers caused:
"An item with the same key has already been added. Key: Content-Type"

Replaces ToDictionary() with manual dictionary population to handle duplicate keys that can occur with HTTP headers (e.g., multiple Content-Type headers).
The last value wins for duplicate keys, maintaining existing behavior.

  • Replaced ToDictionary() with manual dictionary population using indexer assignment
  • Last duplicate key value wins (maintains existing semantic behavior)
  • Performance improvement: O(n) vs O(n log n) complexity
  • No LINQ overhead or intermediate collections

Added test case Log_WhenDuplicateKeysInState_LastValueWins() that verifies:

  • Duplicate keys don't throw exceptions
  • Last value wins for duplicates

User experience

Please share what the user experience looks like before and after this change

Checklist

Please leave checklist items unchecked if they do not apply to your change.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

Replaces ToDictionary() with manual dictionary population to handle duplicate keys
that can occur with HTTP headers (e.g., multiple Content-Type headers).
The last value wins for duplicate keys, maintaining existing behavior.

Performance improvements:
- O(n) complexity instead of O(n log n) from GroupBy
- Single pass enumeration
- No LINQ overhead or intermediate collections

Fixes issue where curl requests with duplicate headers caused:
"An item with the same key has already been added. Key: Content-Type"

Adds test case for duplicate key scenarios.
@boring-cyborg boring-cyborg bot added area/logging Core logging utility tests labels Aug 19, 2025
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 19, 2025
@github-actions github-actions bot added the bug Unexpected, reproducible and unintended software behaviour label Aug 19, 2025
Copy link

Copy link

codecov bot commented Aug 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.45%. Comparing base (dd6d208) to head (9232e86).
⚠️ Report is 17 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #961      +/-   ##
===========================================
+ Coverage    77.39%   77.45%   +0.06%     
===========================================
  Files          271      271              
  Lines        10874    10886      +12     
  Branches      1282     1284       +2     
===========================================
+ Hits          8416     8432      +16     
  Misses        2041     2041              
+ Partials       417      413       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logging Core logging utility bug Unexpected, reproducible and unintended software behaviour size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant