Skip to content

Load CoreMessaging lazily for DispatcherQueue creation - #153

Merged
leileizhang (lei9444) merged 1 commit into
mainfrom
lei9444-lazy-coremessaging-loading
Sep 15, 2026
Merged

leileizhang (lei9444) merged 1 commit into
mainfrom
lei9444-lazy-coremessaging-loading

Conversation

@lei9444

Copy link
Copy Markdown
Contributor

Summary

Remove the existing production static import of CoreMessaging.dll!CreateDispatcherQueueController. Importing the WinRT root or /com entrypoint no longer loads CoreMessaging merely because the unused DispatcherQueue helper is linked into the addon.

  • Resolve the exact export from CoreMessaging.dll with LoadLibraryExW(..., LOAD_LIBRARY_SEARCH_SYSTEM32) only when a current-thread controller must be created. Use the SDK/windows-rs extern "system" ABI and unchanged HRESULT/output conversion.
  • Cache successful resolution and retain its module reference for the process lifetime. Failed exports and concurrent losing candidates release their temporary references; failed requests remain retryable. Native loading and controller creation do not run under the cache publication lock.
  • Preserve existing-queue reuse without controller ownership, successful-null versus native-error handling, current-thread/STA options, apartment rules, callbacks, observer teardown, and asynchronous shutdown behavior.

This is a standalone change against main, based on 3f2371025b5690c6bd2708c61d0b4f2fe6747df7. It does not change other optional subsystem loaders, public APIs, generated output, or shared JS sidecars. This is not a general older-Windows support or full addon feature-isolation guarantee.

Regression coverage

Nine new core tests cover deferred missing-DLL/export errors, success-only caching, retries, failed-export cleanup, eight-way concurrent publication with seven losing module releases, unchanged queue-query behavior, and live creation/reuse/callback/shutdown behavior. The live case uses a dedicated initialized STA, pumps through shutdown completion and GetResults, and retires its queue before apartment teardown.

npm run test:imports inspects the real addon import tables with MSVC dumpbin and exercises fresh root/COM imports while accounting for host-preloaded DLLs. CI now runs it after both production x64 and ARM64 release builds, before artifact upload.

Validation

Target Native execution JS addon validation
ARM64 14 focused DispatcherQueue, loader, WinRT, and COM tests passed natively Production release build, PE inspection, fresh Node imports, and 11 existing runtime/async/shutdown tests passed
x64 Same 14 tests passed under Windows ARM64 emulation Production release build and PE inspection passed; x64 Node was not run
i686 Same 14 tests passed under Windows ARM64 emulation Production JS binding cargo check passed; no i686 Node run
  • The untouched production ARM64 addon imported coremessaging.dll!CreateDispatcherQueueController; all three new import regressions failed against it. Both root and /com introduced CoreMessaging into otherwise bare Node processes.
  • Patched ARM64 and x64 production addons have neither the DLL nor the export in ordinary import tables, and zero delay imports. Independently confirmed with pefile; packaged .node bytes match their release DLLs. Both crates' release feature fingerprints are empty: no test-hooks.
  • Patched isolated ARM64 bare/root/COM Node processes keep CoreMessaging absent. All three import regressions pass against the production artifacts.
  • JS declaration/type checks, the WinRT Uri generated-output snapshot, Rust formatting, focused TS formatting/lint, and diff checks passed.
  • Independent code review found no significant issues; the coordinator also reran all nine DispatcherQueue/loader tests and all three import checks and independently verified both packaged PE artifacts.

No OS components, registry settings, global search paths, or user windows were modified to exercise failure cases.

Resolve the system export only when a current-thread controller is needed. Cache successful resolution for the process lifetime, release failed and racing module candidates, and preserve the native HRESULT and queue lifecycle contracts. Cover loader failures, cache races, native shutdown, and production addon import tables.

Copilot-Session: 4e384326-bd2c-4cd0-92c8-3583786a11e1
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Mixed-language test coverage

Workflow status: ✅ Passed

Layer Lines Functions Branches/regions
Rust, including native .pyd/.node 85.59% 81% 85.21% regions
Python aggregate 71.06% n/a 37.9% branches
Python runtime 99.12% n/a 97.37% branches
Generated Python WinRT projections 70.05% n/a 27.07% branches
Generated Python WinRT implementations 72.29% n/a 47.04% branches
JavaScript aggregate 21.98% 25.07% 57.34% branches
JavaScript runtime 38.26% 57.89% 71.01% branches
Generated WinRT projections 22.97% 18.71% 54.94% branches
Generated WinRT implementations 48.66% 59.76% 61.14% branches
Generated Classic COM projections 11.92% 23.97% 54.2% branches

View workflow run and download full HTML/LCOV/XML reports

@lei9444
leileizhang (lei9444) merged commit ee5ac53 into main Sep 15, 2026
24 checks passed
@lei9444
leileizhang (lei9444) deleted the lei9444-lazy-coremessaging-loading branch September 15, 2026 05:20
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.

2 participants