Conversation
Track Windows and Linux leak counts without making the known baseline block unrelated changes. Pin and verify Dr. Memory, retain raw reports, and publish per-scenario summaries for unit tests, functional tests, and SampleCppMini. Files changed: - .github/workflows/memory-leak-analysis.yml - .github/scripts/run-drmemory.ps1 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
Run the expensive analysis only when its workflow or helper changes, so this PR and future maintenance updates exercise both hosted platforms before merge. Files changed: - .github/workflows/memory-leak-analysis.yml Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
Build Linux targets without entering the package deployment path, and ignore Dr. Memory's incomplete Windows bootstrap report while retaining it in the raw artifact. Files changed: - .github/scripts/run-drmemory.ps1 - .github/workflows/memory-leak-analysis.yml Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
Install the Linux curl development dependency, avoid the unrelated installed-package target regression when compiling the sample, and exclude the one functional assertion whose exact asynchronous drop count changes under instrumentation. Files changed: - .github/workflows/memory-leak-analysis.yml Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
Recognize Dr. Memory's clean-report marker and disambiguate SampleCppMini's signed 64-bit EventProperty construction so the same sample compiles under GCC and MSVC. Files changed: - .github/scripts/run-drmemory.ps1 - examples/cpp/SampleCppMini/main.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
Use Windows.Networking.Connectivity for both cost queries and change notifications so network detection preserves behavior without instantiating PublicNetworkListManager or loading netprofm.dll. Fail periodic leak analysis if netprofm returns. Files changed: - lib/pal/desktop/NetworkDetector.cpp - lib/pal/desktop/NetworkDetector.hpp - .github/workflows/memory-leak-analysis.yml Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
Use scoped objects for temporary event and buffer allocations, and destroy the log-session provider during fixture teardown so leak reports represent SDK behavior rather than test fixture ownership. Files changed: tests/unittests/AnnexKTests.cpp tests/unittests/LogSessionDataDBTests.cpp tests/unittests/TransmissionPolicyManagerTests.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
Exercise the real Windows detector so CI proves that WinRT status registration starts, network cost remains valid, shutdown completes, and netprofm.dll is not loaded. Files changed: tests/unittests/NetworkDetectorTests.cpp tests/unittests/CMakeLists.txt tests/unittests/UnitTests.vcxproj Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
Delete the unused NLM interfaces, connection points, callbacks, maps, compatibility branch, and manual reference counting now that network detection is entirely WinRT-based. This reduces object and binary overhead while keeping ownership with unique_ptr. Files changed: docs/building-custom-SKU.md lib/pal/desktop/NetworkDetector.cpp lib/pal/desktop/NetworkDetector.hpp lib/pal/desktop/WindowsDesktopNetworkInformationImpl.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
Avoid spending hosted runner time when main has not changed while preserving manual analysis on demand. Files changed: - .github/workflows/memory-leak-analysis.yml Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
There was a problem hiding this comment.
🟡 Changes recommended
Network-cost behavior regresses for approaching-limit connections, and the leak-analysis coverage has gaps.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Replaces leaking Windows Network List Manager usage with WinRT connectivity APIs and adds automated Dr. Memory reporting.
Changes:
- Migrates Windows network-cost detection and adds regression coverage.
- Adds Windows/Linux leak-analysis workflows with verified tooling and retained reports.
- Fixes test leaks and portability issues.
File summaries
| File | Description |
|---|---|
tests/unittests/UnitTests.vcxproj |
Adds network detector tests. |
tests/unittests/TransmissionPolicyManagerTests.cpp |
Uses stack-owned event contexts. |
tests/unittests/NetworkDetectorTests.cpp |
Tests WinRT detector lifecycle. |
tests/unittests/LogSessionDataDBTests.cpp |
Releases the session provider. |
tests/unittests/CMakeLists.txt |
Includes Windows detector tests. |
tests/unittests/AnnexKTests.cpp |
Adds RAII for allocated buffers. |
lib/pal/desktop/WindowsDesktopNetworkInformationImpl.cpp |
Removes obsolete COM reference counting. |
lib/pal/desktop/NetworkDetector.hpp |
Defines the simplified WinRT detector. |
lib/pal/desktop/NetworkDetector.cpp |
Implements WinRT cost monitoring. |
examples/cpp/SampleCppMini/main.cpp |
Makes integer width explicit. |
docs/building-custom-SKU.md |
Documents WinRT network detection. |
.github/workflows/memory-leak-analysis.yml |
Adds cross-platform leak-analysis jobs. |
.github/scripts/run-drmemory.ps1 |
Runs Dr. Memory and summarizes results. |
Review details
- Files reviewed: 13/13 changed files
- Comments generated: 3
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Restore approaching-data-limit handling in the WinRT cost mapping, verified in lib/pal/desktop/NetworkDetector.cpp. Check netprofm.dll while the detector is active, verified in tests/unittests/NetworkDetectorTests.cpp. Include APITest.C_API_Test in Linux leak analysis after confirming the test passes on Linux, verified in .github/workflows/memory-leak-analysis.yml. Files changed: - .github/workflows/memory-leak-analysis.yml - lib/pal/desktop/NetworkDetector.cpp - tests/unittests/NetworkDetectorTests.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
There was a problem hiding this comment.
🟡 Changes recommended
The asynchronously updated network-cost cache has an unsynchronized read/write data race.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 13/13 changed files
- Comments generated: 1
- Review effort level: Balanced
Store network cost and running state atomically so WinRT callbacks cannot race caller reads. Return the cached cost by value instead of exposing a concurrently updated reference. Verified at: - lib/pal/desktop/NetworkDetector.cpp - lib/pal/desktop/NetworkDetector.hpp Files changed: - lib/pal/desktop/NetworkDetector.cpp - lib/pal/desktop/NetworkDetector.hpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
There was a problem hiding this comment.
🔵 Needs a closer look
The workflow contains an ignored build property, and the new network-cost test does not validate cost mapping or updates.
Review details
Suppressed comments (2)
Previously missed (2) — in code that hasn't changed since the last review.
.github/workflows/memory-leak-analysis.yml:67
MATSDK_USE_WININETis not consumed by any project, props, targets, or source in this repository, so this MSBuild property is silently ignored; the Win32 factory still selects WinInet (lib/http/HttpClientFactory.hpp:27-29). Remove the no-op argument, or wire the intended transport selection into the build before relying on it for this analysis.
tests/unittests/NetworkDetectorTests.cpp:25- This assertion accepts every possible
NetworkCost, so an implementation that always returnsUnknownstill passes and the test does not verify the stated preservation of metered-cost behavior. Add a mocked/injectable WinRT source (or extract the mapping helper) and assert unrestricted, fixed/variable, and roaming/limit mappings, including a status-change refresh.
- Files reviewed: 13/13 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Remove the ignored MATSDK_USE_WININET build property so leak analysis does not imply a transport selection it never made. Extract and test WinRT cost mapping for unrestricted, metered, roaming, over-limit, and approaching-limit states, and verify synchronous refresh updates the cache. Verified at: - .github/workflows/memory-leak-analysis.yml - lib/pal/desktop/NetworkDetector.cpp - tests/unittests/NetworkDetectorTests.cpp Files changed: - .github/workflows/memory-leak-analysis.yml - lib/pal/desktop/NetworkDetector.cpp - lib/pal/desktop/NetworkDetector.hpp - tests/unittests/NetworkDetectorTests.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
There was a problem hiding this comment.
🟡 Changes recommended
Callback teardown has a potential use-after-free, and the DLL regression gate does not reliably detect module loading.
Get a fresh assessment by requesting another Copilot review.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
.github/workflows/memory-leak-analysis.yml:115
- This does not establish that
netprofm.dllwas never loaded. Dr. Memory'sresults.txtonly mentions modules that appear in reported errors/stacks, while the module-loading diagnostics are written toglobal.<pid>.log(and require suitable verbosity); the*.txtfilter excludes those logs. Thus a run that loadsnetprofm.dllwithout a report involving it passes this advertised regression gate. Enable module-load logging and inspect the global logs, or instrument each target to query its loaded modules directly.
- Files reviewed: 13/13 changed files
- Comments generated: 1
- Review effort level: Balanced
Keep per-subscription callback state alive independently, reject callbacks after shutdown starts, and wait for active callbacks before releasing detector resources. Inspect Dr. Memory global module logs for netprofm.dll and require logs for every Windows scenario so the regression gate cannot pass vacuously. Verified at: - lib/pal/desktop/NetworkDetector.cpp - .github/workflows/memory-leak-analysis.yml Files changed: - .github/workflows/memory-leak-analysis.yml - lib/pal/desktop/NetworkDetector.cpp - lib/pal/desktop/NetworkDetector.hpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
There was a problem hiding this comment.
🟡 Changes recommended
Network callback shutdown has unresolved deadlock and exceptional-cleanup hazards.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 13/13 changed files
- Comments generated: 2
- Review effort level: Balanced
Capture COM and atomic cache state by shared ownership so an in-flight notification never dereferences a destroyed detector and teardown does not wait on a callback that can synchronously initiate shutdown. Run Reset from an SEH finally path so subscriptions are disabled and released even when Windows Runtime raises a structured exception. Verified at: - lib/pal/desktop/NetworkDetector.cpp - lib/pal/desktop/NetworkDetector.hpp Files changed: - lib/pal/desktop/NetworkDetector.cpp - lib/pal/desktop/NetworkDetector.hpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
Dr. Memory changes execution speed and caused the one-second storage benchmark to fail at 1.384 seconds even though its functional operations succeeded. Keep the benchmark in normal CI while excluding only that wall-clock assertion from leak analysis. Files changed: - .github/workflows/memory-leak-analysis.yml Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
There was a problem hiding this comment.
🔵 Needs a closer look
The listener uses WinRT objects after initializing only classic COM rather than the required Windows Runtime apartment.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
lib/pal/desktop/NetworkDetector.cpp:234
- The listener now activates and uses Windows Runtime objects, but this initializes only classic COM. Microsoft requires threads that activate/interact with WinRT objects to be initialized with
RoInitialize(orWindows::Foundation::Initialize); relying onCoInitializecan makeGetActivationFactory/later WinRT calls fail on supported systems. Initialize withRoInitialize(RO_INIT_MULTITHREADED)and balance successful calls withRoUninitializeinstead ofCoUninitialize.
- Files reviewed: 13/13 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Use RoInitialize with the multithreaded apartment and balance successful initialization with RoUninitialize so Windows Runtime activation is valid on every supported Windows target. Verified at: - lib/pal/desktop/NetworkDetector.cpp Files changed: - lib/pal/desktop/NetworkDetector.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
There was a problem hiding this comment.
🟡 Changes recommended
The new detector tests fail to compile for supported custom Windows configurations that disable HAVE_MAT_NETDETECT.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 13/13 changed files
- Comments generated: 1
- Review effort level: Balanced
Compile the Windows detector tests only when HAVE_MAT_NETDETECT is enabled so compact custom SKUs that omit the detector still build the test project. Verified at: - tests/unittests/NetworkDetectorTests.cpp - Solutions/build.compact.props Files changed: - tests/unittests/NetworkDetectorTests.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df9f344e-e064-404e-ae6f-c0ef455d747c
Summary
PublicNetworkListManageruse withWindows.Networking.Connectivity, preserving metered-network cost updates without loading the leakingnetprofm.dllmain, with manual dispatch available on demandnetprofm.dllis loaded againValidation
netprofm.dllregression gateKnown instrumentation exclusion
BasicFuncTests.killSwitchWorksremains covered by normal CI but is excluded under Dr. Memory because instrumentation changes its exact asynchronous drop count (400 observed versus 100 expected).OfflineStorageTests_SQLite.StoreThousandEventsTakesLessThanASecondremains covered by normal CI but is excluded under Dr. Memory because instrumentation invalidates its one-second wall-clock performance threshold (1.384 seconds observed).Closes #634
Related external evidence: microsoft/onnxruntime-genai#2590