Skip to content

fix(server): fix the three engine errors the sanitizer job found - #3373

Merged
asclearuc merged 3 commits into
developfrom
fix/RR-3369-sanitizer-findings
Nov 20, 2026
Merged

asclearuc merged 3 commits into
developfrom
fix/RR-3369-sanitizer-findings

Conversation

@asclearuc

@asclearuc asclearuc commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The sanitizer CI job from #3350 reported 5 groups of errors (#3369). This PR fixes the three that are in our code:

  • Factory lookups called a constructor through the wrong function type (UBSan function-type-mismatch, every engine process). makeFactory<Object, Interface> stored a constructor that returns Ptr<Interface> and takes FactoryArgs&&. Factory::find<T> called it as a function that returns Ptr<T> and takes FactoryArgs by value. Interface is often a derived interface (IPipeTask<L>, IPython*Base, IBase*) and T its root (ITask, IServiceEndpoint, …), so both the return type and the parameter differed.
    • Each class that declares FactoryType now also declares using FactoryRoot = <itself>; (7 classes).
    • Factory::Method<I> is the one type of a stored method: it returns Ptr<I::FactoryRoot> and takes I::FactoryRoot::FactoryArgs&&.
    • makeFactory stores static_cast<Method<Interface>>(objectConstructor<Object, Root, Interface::FactoryArgs>), so an interface whose FactoryArgs differ from its root's does not compile.
    • find<T> calls the method as Method<T> and converts the root pointer to T with castMovePtr.
    • The makeFactory overload that took a custom factory function is removed: none of the 82 registrations uses it.
  • engtest and nodetest gave Catch2 a pointer into a freed string (ASan heap-use-after-free at start). TestMain pushed Text(cmdline[0]), a temporary, into the argument list. The path now lives in a named Text until session.run returns.
  • The word DB memory pool freed new[] memory with delete (ASan alloc-dealloc-mismatch). constant_mbr frees each chunk with delete[] on the uint8_t array it allocated.

The other two groups in #3369 are one problem outside our code: the libc++abi.so.1 that CI ships frees a caught exception's message with free, while ASan's operator new allocated it. The follow-up PR handles it in the report script and makes the job required.

Type

fix

Testing

  • Tests added or updated: aptest case "Factory with an interface derived from the factory root" (a class registered under an interface derived from the root, made through the root and found through the derived interface), and a static_assert that both meet at the root's method type. Without the fix the case still passes in a normal build: it runs the call UBSan reported (a constructor stored for a derived interface, called as the root's), so on a regression the sanitizer job is what fails.
  • Tested locally: WSL Ubuntu 22.04, clang 18.1.8, --cmake-config=Sanitize --nodownload, with the sanitizer options of the CI job.
  • ./builder test passes: run under the Linux Sanitize build only; CI runs the three platforms.
Build Sanitizer reports server:test nodes:test
develop, CI run 44405408309 492 in 5 groups passed passed
this PR, WSL 0 passed (aptest 102 cases, engtest 35, nodetest 3) passed (9274 passed, 478 skipped)

The WSL row comes from a full run of this diff without its last two edits (a comment line in Factory.h and the static_assert). After those edits, aptest was rebuilt and its two Factory cases passed with no sanitizer report.

The libc++abi group shows only with the toolchain of the CI runner, so this PR's own sanitizer run (label ci:sanitize) should show that one group and nothing else.

Checklist

  • Commit messages follow conventional commits
  • No secrets or credentials included
  • Wiki updated (if applicable)
  • Breaking changes documented (if applicable)

Linked Issue

Part of #3369

Summary by CodeRabbit

  • Bug Fixes
    • Corrected factory lookups so registered components can be created and accessed through their shared interface hierarchy.
    • Updated factory behavior to return components through the registry’s root interface.
    • Fixed memory cleanup in the indexer’s word database.
    • Prevented test tools from using an invalid executable path while running, avoiding potential crashes.

@asclearuc asclearuc added the ci:sanitize Run the ASan + UBSan sanitizer job on this pull request (add the label, then push) label Nov 19, 2026
@github-actions github-actions Bot added docs Documentation module:server C++ engine and server components tests labels Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor
🤖 Internal: Discord sync marker

Auto-managed by the Discord notification workflow. Stores the linked Discord message ID and forum thread ID. Do not edit or delete.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Factory registration and lookup now use declared factory root types. The indexer memory pool uses matching array deallocation. The test runner retains the executable path while Catch2 reads its argument pointer.

Changes: Factory registry root types

Layer / File(s) Summary
Declare factory registry roots
packages/server/engine-core/apLib/factory/Factory.h, packages/server/engine-core/test/factory/Factory.cpp, packages/server/engine-lib/engLib/monitor/Monitor.hpp, packages/server/engine-lib/engLib/store/headers/endpoint.hpp, packages/server/engine-lib/engLib/store/headers/filter.hpp, packages/server/engine-lib/engLib/stream/iStream.h, packages/server/engine-lib/engLib/task/headers/task.hpp
Factory interfaces declare FactoryRoot aliases. Factory::Method uses the root type and its arguments.
Register and look up root-typed methods
packages/server/engine-core/apLib/factory/Factory.h, packages/server/engine-core/apLib/factory/Factory.hpp, packages/server/engine-core/test/factory/Factory.cpp, CHANGELOG.md
Factory registration and lookup use the root-typed method. The test checks method type compatibility and creation through root and intermediate interfaces. The changelog records the factory change and the two runtime fixes.

Indexer memory pool deallocation

Layer / File(s) Summary
Match chunk deallocation to allocation
packages/server/engine-core/apLib/memory/pmr.hpp
The memory pool releases chunks with delete[].

Test executable-path lifetime

Layer / File(s) Summary
Retain the executable path
packages/server/engine-lib/test/testMain.ipp
TestMain stores the executable path in a local Text while cmdArguments holds its pointer.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

Merge Risk: Minimal · up to 2237e

This change fixes three sanitizer-reported memory and type-safety problems in the server engine and tests. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change: fixing three engine errors found by the sanitizer job. The changeset matches this. It fixes the Factory function type mismatch (FactoryRoot, Factory::Method, find/makeFacto…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: fixing three engine errors found by the sanitizer job. The changeset matches this. It fixes the Factory function type mismatch (FactoryRoot, Factory::Method, find/makeFactory changes), the Catch2 use-after-free in testMain.ipp, and the word DB delete[] mismatch in pmr.hpp. The title is broad and does not name the three fixes, but it refers to real changes and is not vague or off-topic.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between bbef557 and 2237e3a.

Files selected for processing: 1

  • CHANGELOG.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

- Each class that declares `FactoryType` also declares `FactoryRoot`
- `makeFactory` stores and `find` calls a `Factory::Method<I>`, the root's type
- Remove the unused `makeFactory` overload with a custom factory function
- aptest case for an interface derived from the factory root

Part of #3369
`TestMain` keeps the path in a named `Text` until `session.run` returns.

Part of #3369
@asclearuc
asclearuc force-pushed the fix/RR-3369-sanitizer-findings branch from bbef557 to 2237e3a Compare November 19, 2026 21:23

@dsapandora dsapandora left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you @asclearuc. Storing and calling every factory method at the root's type, with the static_cast refusing an interface whose FactoryArgs differ, removes the mismatch at its source, and the two memory fixes free what was allocated, the way it was allocated. On this PR's sanitizer run all 72 reports are ~range_error freed in libc++abi at __cxa_end_catch; none of the three groups fixed here is left.

Approve

nit, no changed line to sit on: the new aptest case passes on the old code in a normal build, so the sanitizer job is the only thing that catches a regression here. Making it required in the follow-up is what keeps these fixed.

@asclearuc
asclearuc merged commit d6c836c into develop Nov 20, 2026
54 of 61 checks passed
@asclearuc
asclearuc deleted the fix/RR-3369-sanitizer-findings branch November 20, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:sanitize Run the ASan + UBSan sanitizer job on this pull request (add the label, then push) docs Documentation module:server C++ engine and server components tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants