Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
Bug Assessment: Review findings on the engine rebuild (#212)
- Slug: pr212-review
- Created: 2026-10-20
- Source: review of https://github.com/nota-daw/nota/pull/212 (host: github.com — allowlisted), list pasted by the maintainer
- Verdict: valid
- Severity: high (use-after-free on the audio thread; ARM64 data race), the rest low
Report (summarized)
Findings left on the merged PR #212 (64250a5):
- Use-after-free:
ensureTrackScratch(Engine.cpp:601) reallocatesleafBuf_/leafWork_on the message thread insidepublishRawwhile the audio thread and pool workers write the current block into them. Adding a track during playback can corrupt memory or crash. AudioThreadPoolordering:done_.fetch_addisrelaxed, so the caller's acquire load has nothing to synchronise with; on ARM64 the accumulate can read half-written worker buffers. Fix:releasein both places.- Workers spin forever — already fixed in
idle-pool-spin(#223). - The parallel-render eligibility check doesn't look inside racks; v4 racks can hold hosted plugins, which would then run on a pool thread.
stageSilent_is computed every block but never read — wasted passes on the RT thread.- Pool scratch is reserved but unused.
- Scanner dead code, including a second
indexOfIdwith different logic. - Two copies of
AudioPluginFormatManagerin the plugin host. instantiateCatalogcopies the whole catalog for one entry and is TOCTOU-prone.- CI not updated for CPM: no cache,
submodules: recursiveleft over, JUCE/flac/miniaudio pinned by tag instead of commit.
Symptom
(1) memory corruption / crash when the track count grows while audio renders; (2) possible torn reads of worker output on ARM64; (4) a hosted plugin inside a rack processed off the audio thread; (5)–(9) wasted RT work and maintenance hazards; (10) slow, unpinned CI dependency fetches.
Reproduction
- Start playback with N tracks, add tracks until N exceeds the previous high-water mark — the
std::vectorgrowth inensureTrackScratch/ensureMidiScratchfrees the buffers the audio thread holds. (Not reproduced as a crash here; it is a code-evident race.) - Put a VST3/AU inside an Audio Effect Rack on a track:
RackDevice::builtinKind()is 5, so the track is marked eligible and the rack (with its plugin) runs inpool_.dispatch. - Others: read the code paths below.
Suspected Code Paths
src/native/nota.engine/src/engine/Engine.cpp:584-604ensureMidiScratch/ensureTrackScratch— growblockMidi_,blockExpr_,blockMidiN_,blockExprN_,leafWork_,leafBuf_in place frompublishRawwhileprocessBlockmay be mid-block on the audio thread.blockMidi_/blockExpr_have the same flaw as the two named in the report (outer vector reallocation).src/native/nota.engine/src/engine/AudioThreadPool.h:dispatch()and.cpp:workerLoop()—done_.fetch_add(1, relaxed).src/native/nota.engine/src/engine/Engine_Render.cpp:2163-2175— eligibility usesinstrument->kind() < 0anddevice->builtinKind() < 0; racks (RackDevice5,RackInstrument3,DrumRack) pass even when a chain holds a plugin.Engine_Render.cpp:1777,2310,2385,2476,Engine.h:1776-1777—stageSilence_/stageSilent_written only.AudioThreadPool.{h,cpp}reserveScratch/workerScratchBuffer/scratch_;Engine.cpp:25,602.pluginhost/scanner/OutOfProcessScanner.{h,cpp}ScanResult,scanOne;pluginhost/scanner/PluginCatalog.{h,cpp}snapshot,hasFileOrIdentifier, freecatalog::indexOfId(suffix match instead of format+name+hex-uid);bridge/PluginCatalogBridge.h.pluginhost/scanner/abi_pluginscanner.cpp:formatManager()vspluginhost/hosting/PluginCommon.cpp:sharedFormatManager().pluginhost/hosting/PluginCommon.cpp:instantiateCatalog(catalog.types()deep-copies every description) andPluginHost.cpp:createPluginInstrument(entryAttheninstantiateCatalogunder two separate locks: a scan in between shifts indexes)..github/workflows/ci.yml,.github/workflows/release.yml,src/native/nota.engine/cmake/dependencies.cmake.
Root Cause Hypothesis
Confidence: high for all items — each is visible in the code as described.
Proposed Remediation
Preferred:
- Move the per-block render scratch (leaf work + leaf buffers + MIDI/expression pre-pass buffers)
into one
RenderScratchobject published through the engine's existingSnapshotHistory(message thread builds a bigger one with headroom, publishes it before the graph swap; the audio thread reads it once per block after loading the graph and ends the block with aRenderScope; retired scratch is freed two renders later). Nothing the audio thread holds is ever reallocated. done_.fetch_add(1, std::memory_order_release)in the worker and caller claim loops.- Add
virtual bool hostsPlugin() consttoDevice(defaultbuiltinKind() < 0) andInstrument(defaultkind() < 0); racks override it by walking their live snapshot recursively. The eligibility check uses it. - Remove
stageSilence_/stageSilent_and the four detector passes. - Remove the pool's scratch API.
- Remove the dead scanner code and the JUCE-free bridge it was the only user of.
- The scanner ABI uses
hosting::sharedFormatManager(). PluginCatalog::typeAt(index, out)copies one description under one lock; instantiation checks instrument-ness on that same copy.- CI: drop
submodules: recursive, setCPM_SOURCE_CACHEand cache it withactions/cachekeyed ondependencies.cmake; pin miniaudio, flac, JUCE by commit SHA (tag in a comment).
Files likely to change: Engine.{h,cpp}, Engine_Render.cpp, AudioThreadPool.{h,cpp},
devices/Device.h, devices/Instrument.h, devices/racks/RackCore.h, RackDevice.h,
RackInstrument.h, pluginhost/scanner/*, pluginhost/bridge/PluginCatalogBridge.h,
pluginhost/hosting/PluginCommon.{h,cpp}, PluginHost.cpp, cmake/dependencies.cmake,
.github/workflows/{ci,release}.yml.
Tests to add or update:
- Throwaway harness: grow the track count repeatedly while a second thread renders (ASan) — no errors.
- Pool stress harness from
idle-pool-spinstill passes. scripts/build.shsmoke test (renders end-to-end, scans plugins, rack round-trips).
Risks & Considerations
- Scratch headroom costs memory: 256 KB per track slot (kMaxBlock 16384 × 4 floats); growth rounds up to multiples of 8 tracks.
- Retired scratch is freed only on the next publish (SnapshotHistory semantics) — one extra copy may linger.
- The rack walk runs on the audio thread once per block per rack — reads only, no allocation.
- Not addressed here: pool workers run at normal priority while the audio callback waits for them (priority inversion). Needs per-platform priority work (macOS audio workgroups, Windows MMCSS, Linux SCHED_FIFO) — follow-up.
Open Questions
- None blocking.