docs(wiki): park-2 event-loop stall incident + bounded-request-cost decision; Dingtian firmware retired, dev-board pinout, edge-controller memo
- concepts/park-2-event-loop-stall: /api/sessions/active ~2 s synchronous (quote() per open unpaid transient x664, unindexed ledger scans) froze the loop; Node runs expired timers before queued UDP replies, so healthy Dingtian pulses reported "timeout" and signed entries lost their snapshot/session row. Standing decision: bounded request cost whatever the operator data. - Dingtian: custom firmware retired (2026-10-23), runbook shelved, vendor pinout in raw/, relay-proxy PoC marked retired; edge-controller hardware memo (open).
This commit is contained in:
@@ -266,3 +266,8 @@ off the latest payment. See [[tariff]] (walk-back grace) for the pricing side of
|
||||
auto-printed at payment. `POST /api/voucher`, `POST /api/receipt`.
|
||||
- Open: a force-open **override** (lost ticket / equipment fault) — deferred; would be a separately
|
||||
audited signed event, not folded into the validated path.
|
||||
|
||||
> **Performance note (2026-10-24).** `activeSessions()` prices every open unpaid transient from
|
||||
> ONE ledger scan (rows grouped per identity → `#quoteFromRows`), never `quote()` per row. The
|
||||
> per-row version grew with the operator's open-ticket count and froze park-2's server at ~2 s
|
||||
> per call — see [[park-2-event-loop-stall]].
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
type: concept
|
||||
tags: [parking, hardware, runbook, esp32, dingtian]
|
||||
sources: []
|
||||
updated: 2026-10-22
|
||||
updated: 2026-10-23
|
||||
---
|
||||
|
||||
# Runbook — Is this ESP32 board flashable? (Dingtian DT-R0xx lock test)
|
||||
|
||||
> **Shelved 2026-10-23** — custom Dingtian firmware is retired (user decision, mini PCs instead).
|
||||
> Kept as reference; never run on the bench unit.
|
||||
|
||||
A bench test that answers one question in a few minutes: **is the ESP32 on this [[dingtian-relay]]
|
||||
locked (standard SKU) or open (Development Board Version)?** Run it before ordering more units or
|
||||
planning any custom-firmware work (see [[dingtian-relay]] "Can we flash our own firmware?").
|
||||
@@ -25,39 +28,53 @@ blocks custom firmware:
|
||||
| `FLASH_CRYPT_CNT` (flash encryption) | flash contents unreadable/unwritable from outside | `espefuse summary` shows it odd/enabled |
|
||||
| `ABS_DONE_0` / `ABS_DONE_1` (secure boot) | ROM only runs a vendor-signed bootloader | `espefuse summary` shows it set |
|
||||
|
||||
The 74HC595 / 74HC165 shift registers on the board are **not** a blocker; community firmware drives
|
||||
them already.
|
||||
On the 2- and 4-channel boards relays and inputs are **direct GPIOs** (DT-R004: relays IO16/IO2/IO32/IO12,
|
||||
inputs IO36/IO39/IO33/IO35, UART IO1/IO3, PHY JL1101 on RMII with IO23 MDC / IO18 MDIO / IO17 clock /
|
||||
IO0 PHY power); only the 8/16/32-channel boards use 74HC595/74HC165 shift registers. Neither is a
|
||||
blocker; community firmware drives both.
|
||||
|
||||
## Equipment
|
||||
|
||||
- USB-to-UART adapter, **3.3 V logic** (CP2102 / CH340 / FT232). Set its jumper to 3.3 V.
|
||||
- Dupont leads. Do **not** connect the 12 V supply; the adapter's 3.3 V powers the ESP32 for this test.
|
||||
- USB-to-UART adapter, **3.3 V logic** (CP2102 / CH343 / FT232; a CH340 clone needs the old
|
||||
WCH 3.4 driver on Windows — see [[relay-proxy-firmware]]). Set its jumper to 3.3 V.
|
||||
- Dupont leads. Do **not** connect the board's 12 V supply; the adapter's 3.3 V powers the ESP32.
|
||||
- A PC with Python: `pip install esptool` (gives both `esptool.py` and `espefuse.py`).
|
||||
|
||||
## Wiring (DT-R0xx programming header)
|
||||
## The debug header (DT-R004) — from the vendor's dev-board repo
|
||||
|
||||
| Adapter | Board |
|
||||
| --- | --- |
|
||||
| GND | GND |
|
||||
| 3V3 | 3V3 |
|
||||
| TXD | RXD (ESP32 GPIO3) |
|
||||
| RXD | TXD (ESP32 GPIO1) |
|
||||
| DTR | NRST (optional; lets esptool reset the board itself) |
|
||||
Source: `raw/dingtian_dev_pinout/` (photos + GPIO table from
|
||||
[dtlzp/relay_dev_demo](https://github.com/dtlzp/relay_dev_demo/tree/master/gpio_pinout)).
|
||||
It is the **unlabelled pin header right next to the ESP32-WROOM-32D module**, left edge of the
|
||||
board under the relays. **There is no BOOT switch on the board** — the only button is `FACTORY`
|
||||
(IO34, the firmware's factory-reset button) and it plays no part in flashing. Download mode is
|
||||
entered the bare-ESP32 way: **IO0 held to GND while NRST is pulsed to GND** (or while power comes
|
||||
up).
|
||||
|
||||
Header labelling varies by revision; confirm against the silkscreen. GPIO1/3 are also the board's
|
||||
Modbus UART, so expect the stock firmware to chatter on them when it boots.
|
||||
| Pin (from the GND end) | ESP32 | Role |
|
||||
| --- | --- | --- |
|
||||
| 1 | GND | ground |
|
||||
| 2 | IO3 | U0RXD — adapter **TX** goes here |
|
||||
| 3 | IO1 | U0TXD — adapter **RX** goes here |
|
||||
| 4 | NRST | reset, active LOW (adapter DTR/RTS or a jumper to GND) |
|
||||
| 5 | IO0 | boot strap — **to GND for download mode** (also RMII_RST/PWR on this board) |
|
||||
| 6 | 3.3V | power in from the adapter |
|
||||
| 7, 8 (V2 boards only) | IO4, IO5 | CAN_RX / CAN_TX — not used for flashing |
|
||||
|
||||
V1 (hw V3.6.8 photo) has the 6-pin row; V2 adds IO4/IO5 for 8 pins. The order is identical.
|
||||
Confirm GND with a multimeter against the terminal-block GND before powering anything.
|
||||
|
||||
## Procedure
|
||||
|
||||
1. Wire as above, adapter unplugged.
|
||||
2. **Hold the board's boot switch** while plugging the adapter into USB. Keep holding ~1 s, release.
|
||||
(Without DTR wired, this is the only way into download mode.)
|
||||
1. Wire as above, adapter unplugged: GND↔GND, 3V3↔3.3V, adapter TX↔IO3, adapter RX↔IO1.
|
||||
2. Jumper **IO0 to GND**. Then either hold **NRST to GND** for a second and release, or simply plug
|
||||
the adapter in (power-on with IO0 low = download mode). If the adapter has DTR/RTS wired to
|
||||
NRST and IO0, esptool can do this itself.
|
||||
3. Identify the port: `COMx` on Windows, `/dev/ttyUSB0` on Linux. On WSL, pass the device through
|
||||
or run from Windows.
|
||||
4. Run:
|
||||
|
||||
```
|
||||
esptool.py --port COM5 --baud 115200 chip_id
|
||||
esptool.py --port COM5 --baud 115200 chip-id
|
||||
```
|
||||
|
||||
5. If it connects, read the eFuses:
|
||||
@@ -66,6 +83,8 @@ esptool.py --port COM5 --baud 115200 chip_id
|
||||
espefuse.py --port COM5 summary
|
||||
```
|
||||
|
||||
6. Remove the IO0 jumper before a normal boot.
|
||||
|
||||
## Reading the result
|
||||
|
||||
**Open (Development SKU):**
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
---
|
||||
type: concept
|
||||
tags: [parking, performance, incident, booth, relay, sqlite]
|
||||
sources: []
|
||||
updated: 2026-10-24
|
||||
---
|
||||
|
||||
# park-2 event-loop stall → phantom relay timeouts (2026-10-24)
|
||||
|
||||
An incident analysis with a durable rule: **request cost must be bounded whatever the operator's
|
||||
data volume**. Found while answering "why do some of a subscriber's entries have no snapshot".
|
||||
|
||||
## Symptom chain (as observed on park-2, stage-9659373)
|
||||
|
||||
1. Four signed `vehicle_entry` events for one subscriber had **no snapshot and no `sessions` row**.
|
||||
2. Each coincided with `relay pulse FAILED … timeout` on the [[dingtian-relay]] and
|
||||
`subscription-flow failed: timeout`. The subscription flow signed the ledger, then awaited the
|
||||
pulse; the pulse helper rethrows, so the method unwound **before** firing the camera and
|
||||
writing the session cache (see [[subscription]], `subscription-flow.ts`).
|
||||
3. The relay was healthy: 60/60 UDP status probes from a separate process answered in 48–52 ms;
|
||||
ping < 1 ms, no loss, link clean.
|
||||
4. The server process was the problem. `GET /api/sessions/active` ran **~2 s, synchronously**,
|
||||
2234× in 24 h (the booth polls it). `PayStation.activeSessions()` called `quote()` **per open
|
||||
unpaid transient** (664 of them), each doing 3–4 **unindexed** `ledger_events` scans by
|
||||
identity. Every other request queued behind it: reader pushes at 2 s, vision calls aborting,
|
||||
forgive at 2 s.
|
||||
5. Node runs **expired timers before pending socket I/O**. A pulse whose reply arrived during the
|
||||
stall saw its 2 s timer fire first → "timeout" for a relay that had answered (and fired).
|
||||
`tookMs` of the failures were 2000–2260 ms — the 2 s timer plus loop lag.
|
||||
6. Growth: open unpaid transients +50–65/day since 2026-10-09 → ~120 ms/day added to the handler.
|
||||
Successful-pulse median tracked it exactly (109 ms on 10-11 → 1330 ms on 10-21; p95 2290 ms on
|
||||
10-24). The curve crossed the 2 s timeout around 10-19/10-22 — when the failures began.
|
||||
|
||||
## Why this is OUR defect (not the operator's)
|
||||
|
||||
The operator's choices (an unlimited card used 70×/day by a booth operator, 664 tickets that
|
||||
never exited through the system) are **theirs to make**. Our defect is any code path whose cost
|
||||
grows with their data. The user's stance, verbatim: "We are not running the business, we are
|
||||
providing the software." Do not propose cleaning up or deciding about operator records.
|
||||
|
||||
## The fix (stage, uncommitted at time of writing)
|
||||
|
||||
- `activeSessions()` prices every row from **one** whole-ledger scan (per-identity grouping fed to
|
||||
a rows-based `#quoteFromRows`) and builds the tariff resolver once. `quote(identity)` wraps the
|
||||
same core with one identity-scoped read, so both paths price identically (pinned by
|
||||
`pay-station.test.ts`). `validations.ts` gained `sessionValidationsFromRows`/
|
||||
`liveValidationsFromRows`.
|
||||
- Migration `0032_hot_path_indexes`: `ledger_events(identity, index)`,
|
||||
`device_events(category, kind, occurred_at)`, `device_events(kind, occurred_at)`,
|
||||
`snapshots(identity)`, `sessions(state)`, `sessions(subscription_id, state)`. Additive; the
|
||||
previous image ignores them on rollback. The snapshots index costs one identity-column pass
|
||||
(~50 ms measured, the blobs live in overflow pages).
|
||||
- Dingtian `binaryUdp`: the timeout rejection is deferred with `setImmediate`, so a datagram that
|
||||
already arrived wins over an expired timer (check phase runs after poll).
|
||||
- Subscription flow: snapshot fired **before** the pulse; session cache written/closed **before**
|
||||
the pulse. Evidence and the projection no longer depend on the relay call succeeding.
|
||||
|
||||
Expected effect on park-2's data: the handler drops from ~2 s to ~0.1–0.15 s (ledger scan 36 ms +
|
||||
plate scan 78 ms, both now index-assisted), and stops growing with open-ticket count.
|
||||
|
||||
## The rule going forward
|
||||
|
||||
- **No per-row ledger reads in list views.** Fold once, price from the fold.
|
||||
- **Every identity/telemetry lookup is indexed.** `ledger_events.identity`, `device_events`
|
||||
(category, kind, time), `snapshots.identity`.
|
||||
- **A device timeout must not race the event loop.** Defer timeout rejections one turn.
|
||||
- **Evidence and projections before the pulse.** The signed event is the decision; the pulse is a
|
||||
side effect that may fail.
|
||||
- Watch `tookMs` on `kind:"relay"` [[device-events]]: a rising median with a healthy device is an
|
||||
event-loop stall, not a network problem.
|
||||
|
||||
## Open follow-ups
|
||||
|
||||
- `GET /api/snapshots/by-identity` still loads **all** camera snapshot/read telemetry rows and
|
||||
filters in JS (45 calls/day, ~50 ms, grows with telemetry). Filter by identity in SQL.
|
||||
- Other `.all()` scans over `device_events`/`ledger_events` in list routes (feed, lane status)
|
||||
deserve the same bounded-work review.
|
||||
- Deploy: build the stage image, bump park-2's TAG (currently stage-9659373; the four commits
|
||||
since touch no app code), watch the pulse `tookMs` and `/api/sessions/active` durations.
|
||||
|
||||
Related: [[booth-exit-flow]] (active list semantics), [[append-only-event-chain]],
|
||||
[[device-events]], [[dingtian-relay]], [[appliance-provisioning]] (park-2 host history).
|
||||
Reference in New Issue
Block a user