fix(hal): await the serial close, and stop reporting a cassette layout the dispenser refused #119
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/dispenser-close-race"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #118.
Two commits, matching the two defects.
1.
close()resolves once the port is actually closed. TheDispenserinterface declaredclose(): void, so no caller could know when the port was free, and neither driver was anywhere near done when it returned. puloon deferredserial.close()behind a 100 mssetTimeout; f56 called serialport's asyncclose()and returned immediately. Both now resolve on the close callback and claim the handle up front so concurrent calls can't double-close. puloon keeps its 100 ms drain — an in-flight write should land before the port goes away — but awaits it.2. A refused layout is no longer kept.
setCassettesupdatedbaysanddispenserInitDatabefore re-initialising the device, on purpose, so dispense calls would see the new layout "even if the dispenser re-init is slow / fails". Since the re-init failed every time on douro, the app held a layout the hardware never took,[OperatorConfig] Applied opswas logged, and acassettes-stateevent advertised it to the operator. This reverses that choice: roll back on failure, let the error propagate. A stale but honest layout beats a fresh but fictional one when the difference is which cassette pays out.Also awaits
dispenser.close()insetCassettesandcleanup().Verified:
tsc --noEmitclean on bothapps/machine/electronandpackages/hal, the 91 electron tests pass, prettier clean.packages/halhas no test files, so the close paths are unverified by tests — worth knowing given #21 (test HAL drivers on physical hardware) is still open.Not yet verified on hardware. The douro is the deterministic reproducer: after this lands, an operator cassette op should log
[HAL] Dispenser re-initialized with new cassettesinstead ofCannot lock port. I'd rather confirm that on the box before this reaches sintra and batm3, since the f56 half changes a code path that four machines use and is not reproducible on demand.Same family as #46 — arbitrary 100 ms timers standing in for real completion signals in the HAL. Worth a sweep at some point; this PR only fixes the dispenser close.