binderth
(Thomas Binder)
November 2, 2026, 1:35pm
21
ok - as far as I (and my Claude) can see, the deadlocks are still present in the current release you mentioned.
After fighting with github for a while, I created two PRs against your “real” repo:
fixing the deadlocks
adding functionality
ad 1)
main ← binderth:fix-protocol-deadlock
opened 10:37AM - 02 Nov 26 UTC
When the connection to the spa breaks while a write is in progress, the binding … deadlocked. From then on every channel command blocked forever and was never sent, every dispose() blocked in disconnect(), and the Thing stayed ONLINE. Disabling and re-enabling the Thing did not recover it (each attempt just left one more blocked OH-safeCall thread); only an openHAB restart did. In practice the spa kept heating on HIGH/36 C for hours while rules were sending LOW.
Observed on openHAB 5.2.3, Java 21, with the jar built from tag v5.2.1-beta.2-ha-parity.2 of the oldfork repository. The lock order involved is unchanged up to v5.2.1.6; the writer fix in 1fde5f5 (NotYetConnectedException) addresses a different failure. Line numbers in the dump below refer to the old build.
Timeline
--------
- WARN BalboaHandler - No data received from the Balboa unit for 107210 ms, assuming the connection is dead -> WatchdogJob calls protocol.disconnect() -> deadlock
- current-temperature froze, Thing stayed ONLINE
- the next command (temperature-range LOW) blocked in startWrite()
- Thing disable/enable: "Disposing handler for thing ... takes more than 5000ms" (6x); the new handler went ONLINE and polled fine, but item commands never produced a "Writing ..." TRACE line again
Thread dump (Karaf `threads`)
-----------------------------
"Thread-29460" BLOCKED on BalboaProtocol@63e0721c
owned by OH-thingHandler-25916
at BalboaProtocol.disconnect(BalboaProtocol.java:664) at BalboaProtocol$Writer.failed(BalboaProtocol.java:355)
- locked BalboaProtocol$Writer@2567e875 at sun.nio.ch.Invoker.invokeDirect(Invoker.java:160) at sun.nio.ch.AsynchronousSocketChannelImpl.write(...) at BalboaProtocol$Writer.completed(BalboaProtocol.java:343)
- locked BalboaProtocol$Writer@2567e875
"OH-thingHandler-25916" BLOCKED on BalboaProtocol$Writer@2567e875
owned by Thread-29460
at BalboaProtocol$Writer.reset(BalboaProtocol.java:241)
at BalboaProtocol.disconnect(BalboaProtocol.java:681)
- locked BalboaProtocol@63e0721c at BalboaHandler$WatchdogJob.run(BalboaHandler.java:241)
Blocked behind them: the command (OH-safeCall ...
TemperatureRange.handleCommand -> sendMessage -> Writer.startWrite:291), the poller (PollingJob.run -> startWrite), Reader.failed -> disconnect, and one BalboaHandler.dispose -> disconnect:664 per Thing restart.
Root cause
----------
Two monitors were taken in opposite order:
Writer.completed() [Writer] -> socket.write() fails synchronously on
the same thread (Invoker.invokeDirect) -> Writer.failed() [Writer]
-> disconnect() [needs BalboaProtocol]
WatchdogJob / dispose() / Reader.failed() -> disconnect()
[BalboaProtocol] -> writer.reset() [needs Writer]
The watchdog fires when the socket is half dead, which is exactly when a pending write fails, so the race is hit in practice.
The same pattern exists between BalboaHandler.ReconnectJob and the protocol: ReconnectJob.run() is synchronized and calls connect() [needs BalboaProtocol], while connect()/disconnect() hold the protocol monitor and call back into ReconnectJob.schedule() via setStatus() -> onStateChange() [needs ReconnectJob]. A reconnect firing while the watchdog disconnects deadlocks the same way.
Fix
---
- Writer and Reader no longer have monitors of their own. All their state is guarded by the enclosing BalboaProtocol's monitor, which connect() and disconnect() already hold. The failing-write path and disconnect() now re-enter the same monitor instead of waiting for each other. AsynchronousSocketChannel invoking failed() directly from inside socket.write() is fine for the same reason (reentrant).
- The connect-failed callback sets socket = null and resets reader and writer under that same monitor, like every other access to the socket field.
- ReconnectJob.run() only holds its own monitor while clearing the pending job, not while connecting.
No functional change otherwise: queueing, the queue limit, the synchronous write failure handling from 1fde5f5, logging, reconnect backoff, configuration timeout and the watchdog behave as before.
BalboaProtocolDeadlockTest recreates the interleaving deterministically (one thread holds the protocol's monitor like disconnect() and resets the writer, while another runs the writer's failure callback). It fails on v5.2.1.6 ("disconnect path deadlocked against the writer's failure callback") and passes with this change. mvn verify passes, all 36 tests.
simple => just added the changes here to prevent deadlocks from happening: writer against protocol and reconnect against protocol. there’s also a new BalboaProtocolDeadlockTest included, which should test for those.
ad 2)
main ← binderth:clock-state-control
opened 01:27PM - 02 Nov 26 UTC
New channels, built like the existing ones (labels and option labels in balboa.p… roperties / balboa_de.properties):
- state: spa-state, notification, panel-locked, heat-state
- control: hold-mode, clear-notification, circulation-switch (only if the unit reports a circulation pump), filter-2-enabled-switch
- clock: spa-time (read/set), clock-24h, clock-offset; the new thing option syncClock sets the unit's clock to the openHAB time (time zone from the regional settings) whenever it is off by more than a minute, e.g. after a daylight saving change
- fault log: fault-count
- advanced: low/high-range-min/max, model, software-version, mac-address
- filter-1/2-start and -duration are writable (HH:MM)
Fixes:
- priming tested bit 0 of the initialization mode, so a pending reminder (0x03) was reported as priming. Now only for mode 0x01.
- Target temperatures were clamped to fixed limits (low range 26 °C). They are now clamped to the limits the unit reports (setup parameters, e.g. 10-37 °C on a BP601G1); the fixed limits remain the fallback until those arrive.
- READY_IN_REST to READY takes two toggles, as in pybalboa.
- The system information response (0x24) is decoded; setup parameters (0x25) and module identification (0x94) are requested on connect. Settings responses that arrive before the channels are built are cached and replayed once they exist.
Decoding follows pybalboa (garbled1/pybalboa) and the community protocol documentation (ccutrer/balboa_worldwide_app). Tests cover the new outbound payloads and the decoding, partly with messages captured from a BP601G1. mvn verify passes with 44 tests and no static analysis findings.
added some new features around the clock, reading states and writing stuff like filters, etc. all described in the PR - and also tests for it.
runs on my environment over the weekend without problems.
Larsen
(Locke)
November 2, 2026, 5:24pm
22
hey cool. The changes are really usefull.
And Claude confirms that the changes from you and Claude really improve the binding which is made by Claude
I merged everything and created a new 5.2.1.7.
Please test and tell me if it works for you. I just changed to this version and it seems to work within my system.
binderth
(Thomas Binder)
November 2, 2026, 5:49pm
23
it’s basically running since friday. But I’ll update it with your 5.2.1.7 to be sure.
for others following: it’s an AI-improved version of the initial Balboa-binding, now without two potential errors and improved functionalities (e.g. more channels and clock syncronisation), current release:
Patch release for openHAB 5.2 with two contributions by @binderth (#1, #2).
Running on a real spa since 2 November 2026; the new channels and controls are not tested on a real spa yet, please
repor...