Repository navigation
fix(test): SPI ping-pong polling-path infinite loop + UBSan overflow - #2843
Conversation
…verflow
stepStreaming's polling branch derived the just-drained buffer from
`encodeIdx & 1`, which alternates A/B independently of which buffer was
actually in flight. In polling mode startFirstDma() only queues A, so:
step 1: alternation says "drain A" → matches reality (transA=true)
step 2: alternation says "drain B" → transB was never queued, no-op,
but refill still encodes a B chunk and sets transB=true → now
BOTH A and B in flight, violating polling's "1-in-flight"
invariant.
After ledBytesRemaining hits 0, encodeIdx stops advancing (no refill
happens), so the alternation gets stuck pointing at whichever buffer
isn't in flight. anyInFlight() stays true forever and the test loop
spins, incrementing `++completedCount` until UBSan trips on int
overflow at line 126. This was masking the underlying model bug as a
"signed integer overflow" runtime error in CI.
Fix: drop the encodeIdx-based polling branch entirely and share the
async drain logic — drain whichever buffer is actually in flight (A
first, mirroring the ESP-IDF FIFO). The polling path's distinguishing
behavior is already captured in startFirstDma()'s pre-queue decision
(line 92); stepStreaming doesn't need to know the mode.
All 227 unit tests pass after this change.
|
Ready to act? Review this PR in Change Stack to turn feedback into patch suggestions you can inspect and refine. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe change refactors the ChangesPipelineModel streaming drain buffer selection fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Infer (1.2.0)tests/platforms/esp/32/drivers/spi/spi_pingpong_pipeline_logic.cpptests/platforms/esp/32/drivers/spi/spi_pingpong_pipeline_logic.cpp:25:10: fatal error: 'fl/stl/cstddef.h' file not found ... [truncated 1178 characters] ... l-isystem" "/usr/local/include" "-internal-isystem" 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. Comment |
Closes FastLED#2824. PR FastLED#2843 already fixed the polling-drain logic bug (the encodeIdx-based branch that produced the infinite loop). This closes out the issue's "Additional defense" recommendation: add the same `safety` counter + `stepStreaming()` return-value guard that's already in the queue-depth test (line 226) to the two drain-all loops that don't yet have it. Without the guard, a future regression of the same shape would manifest as a 20 s runner-watchdog timeout (the original FastLED#2824 symptom). With it, the loop bails after 1000 iterations with a clear `FL_CHECK_GT(safety, 0)` assertion in milliseconds. Affected test cases: - "Ping-pong - all bytes accounted for after drain" (line 248) - "Ping-pong - polling path drains all bytes" (line 268, the original FastLED#2824 hang site) The 1000-iteration cap leaves generous headroom — a 4 KB-capacity strip of 12345 bytes drains in ~25 ping-pong steps; 8000 bytes polling drains in ~16. Any regression that crosses 1000 is the same class of bug that FastLED#2824 caught. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Fixes the `spi_pingpong_pipeline_logic` test failure that has been blocking unrelated PRs (e.g. #2840, and previously surfaced in #2838's local builds).
`stepStreaming`'s polling branch derived the just-drained buffer from `encodeIdx & 1`, which alternates A/B independently of which buffer was actually in flight. In polling mode `startFirstDma()` only queues A, so:
```
step 1: alternation says "drain A" → matches reality (transA=true)
step 2: alternation says "drain B" → transB was never queued, no-op,
but refill still encodes a B chunk and sets transB=true → now
BOTH A and B in flight, violating polling's "1-in-flight"
invariant.
```
After `ledBytesRemaining` hits 0, `encodeIdx` stops advancing (no refill happens), so the alternation gets stuck pointing at whichever buffer isn't in flight. `anyInFlight()` stays true forever and the test loop spins, incrementing `++completedCount` until UBSan trips on signed-int overflow at line 126. That's the "signed integer overflow: 2147483647 + 1" failure mode CI has been hitting.
Fix
Drop the `encodeIdx`-based polling branch entirely and share the async drain logic — drain whichever buffer is actually in flight (A first, mirroring the ESP-IDF FIFO). The polling path's distinguishing behavior is already captured in `startFirstDma()`'s pre-queue decision (line 92); `stepStreaming` doesn't need to know the mode.
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit