Skip to content

test hang: spi_pingpong_pipeline_logic polling-path drains wrong buffer, loops forever (regression in #2810) #2824

Closed

Description

@zackees

Summary

`tests/platforms/esp/32/drivers/spi/spi_pingpong_pipeline_logic.cpp` test case "Ping-pong - polling path drains all bytes" (line 266) hangs in an infinite loop until the runner watchdog fires at 20 s. Added by #2810 (commit `f0692ed95c`).

The hang blocks `bash test --cpp` Stop-hook runs on Windows (and likely all hosts).

Repro

```
bash test spi_pingpong_pipeline_logic
```

Stack trace (truncated):
```
#0 PipelineModel::stepStreaming() + 173
#1 _fl_func_6() + 127 ← "polling path drains all bytes"
#2 fl::function::FreeFunctionCallable::invoke()
...
RUNNER WATCHDOG TIMEOUT (Test exceeded runner timeout of 20.0 seconds)
```

Root cause

In `PipelineModel::stepStreaming()` at lines 117-120:

```cpp
if (usePolling) {
int lastBuf = (encodeIdx - 1) & 1;
if (lastBuf == 0) { transAInFlight = false; drainedBuf = 0; }
else { transBInFlight = false; drainedBuf = 1; }
}
```

Polling-mode `stepStreaming()` picks the buffer to drain from `encodeIdx & 1`, which alternates 0, 1, 0, 1, ... But `startFirstDma()` at line 92 explicitly guards the B pre-queue with `!usePolling` — in polling mode, only A is ever queued by `startFirstDma()`.

What happens in the failing test (`TOTAL_BYTES = 8000`, `capacity = 4096`, `polling = true`):

Iter encodeIdx lastBuf What it does transA transB
start 1 — startFirstDma queues A t f
1 1 0 drain A, refill A → encodeIdx=2 t f
2 2 1 "drain B" (no-op, B was never true), refill into B → encodeIdx=3 t t ⚠️
3 3 0 drain A, refill A → encodeIdx=4 t t
4 4 1 drain B, refill B → encodeIdx=5 t t
... (alternates A/B, both stay in flight) t t
K last refill into B; `ledBytesRemaining = 0` t t
K+1 even 1 drain B; no refill (no bytes left) t f
K+2 even 1 "drain B" (no-op, already false); no refill; return true t f
K+3 even 1 same as K+2 — infinite loop t f

The outer loop:

```cpp
while (m.anyInFlight() || m.ledBytesRemaining > 0) {
m.stepStreaming();
}
```

stays in iteration K+2 forever: `anyInFlight()` is true (A is in flight), `ledBytesRemaining` is 0, and `stepStreaming()` keeps "draining B" (already false) and never touches A because `(encodeIdx - 1) & 1` is always 1.

Proposed fix

The polling branch should drain the buffer that's actually in flight, not the one indicated by `encodeIdx`. Same logic as the FIFO branch already does — both modes converge on "drain whatever is in flight, prefer A if both happen to be":

```cpp
// In both polling and async (FIFO) modes: drain the buffer that's actually
// in flight. In async mode A completes first if both are queued; in polling
// mode only A is ever queued so this resolves to A trivially.
if (transAInFlight) { transAInFlight = false; drainedBuf = 0; }
else if (transBInFlight) { transBInFlight = false; drainedBuf = 1; }
```

Effectively delete the `if (usePolling)` branch and use the existing `else` logic for both modes. The `encodeIdx` field is still useful for accounting/debugging but should not steer the drain selection.

Additional defense

The outer loop in the test (line 252-254 and line 272-274) should also defend against infinite loops by using a safety counter or by checking the return value of `stepStreaming()` — the test case at line 224 already does this:

```cpp
int safety = 100;
while (m.anyInFlight() || m.ledBytesRemaining > 0) {
...
if (!m.stepStreaming()) break;
if (--safety <= 0) break;
}
FL_CHECK_GT(safety, 0); // didn't loop forever
```

Adding the same guard to the drain-all tests would fail fast with a clear assertion instead of waiting 20 s for the runner watchdog.

Acceptance criteria

Out of scope

This is purely a test-side state-machine bug; the production driver in `src/platforms/esp/32/drivers/spi/channel_driver_spi.cpp.hpp` is not affected. The test was meant to mirror driver behavior but its polling-path mirror diverged.

Why I'm not fixing it in #2822

#2822 is the compilation-Docker decommission PR — touches zero files under `src/` or `tests/`. Bundling an unrelated test fix would obscure that PR's diff and make it harder to bisect. Filing this so the test author / driver owner can take it.


Discovered while #2822's Stop hook flagged the hang. Not blocking the Docker decommission PR — the hang predates it.

Activity

  1. added a commit that references this issue on Jun 6, 2026
  2. moved this from Triage to Done in FastLED Trackeron Jun 6, 2026
  3. added a commit that references this issue on Jun 6, 2026
    9be4fa7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions