Skip to content

Fix duplicate module IDs in error events - #395

Open
niemyjski wants to merge 8 commits into
mainfrom
feature/fix-duplicate-module-ids
Open

niemyjski wants to merge 8 commits into
mainfrom
feature/fix-duplicate-module-ids

Conversation

@niemyjski

@niemyjski niemyjski commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Loading the same DLL twice could give both modules one ID and leave an inner frame unresolved. Each error now owns its module IDs and resolves frames by assembly instance. Unreadable metadata skips only the affected assembly.

All six CI checks passed on 0445370. Locally, 160 error-plugin and serializer tests passed with 12 existing skips. Windows runtime results

Warm conversion took 31% less time than main at 256 modules and 34% less at 768. At 1,536, above the cache cap, it took 2.722 ms versus 1.323 ms on main. Concurrent reports of the same exception can still produce duplicate events.

Verification and implementation details

Module identity and cache lifetime

A module’s ID is its 1-based position in the current error. A name hash cannot distinguish two loads of the same DLL. When module capture is enabled, each top-level error enumerates the currently loaded assemblies once. Inner exceptions and Framework target methods share that error’s assembly list. Its assembly references go out of scope after conversion. The frame assignment calls GetModuleId(moduleAssemblies, methodBase). The helper returns -1 before touching reflection when module collection is disabled and returns the same sentinel for an unmatched frame.

The shared cache holds at most 1,024 paths with their manifest module version IDs and metadata snapshots. A cache hit requires both the current path and the loaded DLL’s MVID to match, so a rebuild at the same path refreshes its metadata. A hit skips both version-attribute reads. Every event gets its own mutable module and data dictionary. Cache insertion, replacement and FIFO eviction take the same lock. Readers work from a fully initialized snapshot. File access, reflection and event serialization stay outside the lock. System, generated, locationless and dynamic assembly filters still apply.

Reflection and file metadata

  • Main's singular version getter works for normal assemblies. It throws AmbiguousMatchException on a DLL with a repeated version attribute. The two readers now share one private helper. It calls GetCustomAttributes once for the requested type and uses the value only for exactly one match. Both attributes are single-use. The SDK tries the informational version first, then the file version, then the assembly identity version, skipping a source if its attribute is absent or repeated. Microsoft’s singular lookup contract
  • The generated-code filter needs only the presence of GeneratedCodeAttribute. IsDefined answers that directly and avoids building the old list of attribute instances. The two version readers still read the values.
  • With one attribute of each kind, reading both version fields took 0.847 µs and 528 B, against 0.868 µs and 528 B on main. On duplicate informational versions, the helper took 1.113 µs and 792 B. A trial using the singular getter and catching the exception took 4.460 µs and 1,496 B. These were uncached reads, measured across seven fresh processes per case.
  • The normal file path reads both timestamps from one FileInfo. A cold capture with 768 modules took 4.245 ms, against 5.794 ms in an otherwise identical build using separate timestamp reads. Both original timestamp fallbacks remain available. The comparison used eleven fresh processes per build.

Regression coverage

The new tests use Operation_Scenario_Outcome names and Arrange, Act, Assert phases. They emit DLLs during the run and capture through the SDK error plugin and serializer. Cases include one DLL loaded twice, different files with the same assembly identity, rebuilding a DLL at the same path, Framework AppDomain unload, collectible load contexts, mutations in four simultaneous captures, generated and locationless assemblies, malformed attributes, and all three version outcomes. Windows passed 306 SDK tests on .NET 10 and 294 on .NET Framework 4.7.2, with 17 existing skips on each target.

The local stress probe generated 1,280 modules across 40 collectible contexts. Workers retained 320 mutated and JSON-checked events while another worker captured 3,423 errors during load and unload. All 40 contexts were collected with the events alive. The cache peaked at 1,024 and its FIFO keys matched its entries. In eight concurrent errors with a malformed attribute on the inner assembly, the healthy outer frame resolved every time. Eight simultaneous calls with a shared exception object produced eight events on both main and the PR. Every event from that probe had unique module IDs. All local event payloads stayed in memory.

Performance and retention

Modules Warm conversion on main Warm conversion on this PR
256 0.263 ms 0.181 ms
768 0.724 ms 0.480 ms
1,536 1.323 ms 2.722 ms

Measurements used Release on macOS arm64 with .NET 10.0.14. Each process emitted fresh DLLs. Warm timings are medians of five processes per revision and size with rotated run order, 150 warm-up errors and seven timed batches of 200. The earlier CPU profile identified repeated assembly-name reflection on cache hits. Its share of sampled conversion time fell from 41.2% on main to 5.8% after reusing cached metadata.

After the synthetic load context unloaded, the cache exclusively retained a median of 572,072 managed bytes at 768 entries and 783,576 bytes at 1,024 entries. With 1,536 modules emitted it still held 1,024 entries and retained 783,224 bytes. Each median covers five fresh processes. A diagnostic build released both cache roots and measured which managed objects were collected. Path lengths, metadata strings, and dictionary storage affect the totals.

An earlier end-to-end comparison on 3dd1949 measured 9.459 ms for 768-module conversion and JSON serialization, against 10.133 ms on main. Individual process times overlapped substantially.

dotnet test test/Exceptionless.Tests/Exceptionless.Tests.csproj -c Release --filter 'FullyQualifiedName~Exceptionless.Tests.Plugins.ErrorPluginTests|FullyQualifiedName~Exceptionless.Tests.Serializer'

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T22:30:38.142138Z d5c7462 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0f76250858

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

var module = assembly.ToModuleInfo();
var module = CreateModule(assembly, name, publicKeyToken);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve metadata caching while creating event-local modules

With the default IncludeModules = true, every exception conversion now calls CreateModule for every included assembly, repeating custom-attribute reflection and filesystem timestamp reads that previously occurred only on a cache miss. ExceptionlessClient.SubmitEvent runs ErrorPlugin synchronously before queueing, so applications with many loaded assemblies or frequent exceptions pay this additional work on the submitting thread for every event, including events subsequently discarded by duplicate checking. Keep module records and their dictionaries event-local, but cache immutable assembly metadata using weak assembly-instance keys so collectible assemblies can still unload.

Useful? React with 👍 / 👎.

@niemyjski niemyjski self-assigned this Nov 25, 2026
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.

1 participant