Note · budding
A callback that awaits disconnect deadlocks the connection
- Stage
- budding
- Links
- 1 out, 1 in
The library my LG integration uses calls registered callbacks when the TV’s power state changes. On power-off, the natural thing for a callback to do is close the connection.
That hangs. The callback runs as a task belonging to the connection. disconnect() tears the connection down and waits for the connection’s tasks to finish, and it does so in a loop that shields itself and swallows cancellation. One of the tasks it is waiting for is the callback that called it.
The fix is seven lines: the library starts disconnect() as a separate task from inside the callback path and does not await it there.
I carry the fix in a fork, tagged as a post-release of the upstream version, and the integration depends on that tag by URL until the upstream pull request is merged. I have not reproduced the hang against a physical TV; it was found by reading the code and is covered by a regression test.
Projects
- LG webOS TVs A Home Assistant integration for LG televisions, with picture settings, a pointer remote and calibration controls.
Projects
- LG webOS TVs A Home Assistant integration for LG televisions, with picture settings, a pointer remote and calibration controls.