fix: improve socket reconnection reliability#162
Open
lastowl wants to merge 2 commits intocellcortex:masterfrom
Open
fix: improve socket reconnection reliability#162lastowl wants to merge 2 commits intocellcortex:masterfrom
lastowl wants to merge 2 commits intocellcortex:masterfrom
Conversation
Socket / reconnection fixes: - Reconnect on graceful TCP close (end event), not just on errors — this was the primary cause of devices going permanently offline after a bulb reboot or power cycle - Use reconnect() instead of connect() in the retry path to avoid spawning orphaned sockets while a previous connection attempt is still pending - Destroy and remove listeners from old socket before creating a new one in connect() to prevent duplicate event handler firing - Reject all pending transactions on disconnect to prevent UnhandledPromiseRejection errors and hanging promises (fixes cellcortex#116) Accessory fixes: - Guard setInterval in onDeviceConnected with clearInterval to prevent interval leaks on rapid reconnects - Fix inverted condition in clearOldTransactions (> Date.now() + 60s should be Date.now() - timestamp > 60s) - Fix floodAlarm threshold: 180_000_000ms (50 hours) → 300_000ms (5 min) - Guard error.message access with nullish coalescing to avoid crashes when error has no message property Device support: - Add model spec for plate2 (Yeelight Smart Light Panels) with full colour support and 1700-6500K CT range (fixes cellcortex#157)
e5dc939 to
c037da7
Compare
- Add AdaptiveLightingController to ColorLightService when ctforcolor is enabled — color lights (e.g. Bulb 1S, Bedside Lamp D2) previously had no Adaptive Lighting support even with CT enabled (fixes cellcortex#144) - Add model specs for color8/colora (W3 Color Lightbulb) with full colour and 1700-6500K CT range (fixes cellcortex#155) - Add model spec for bslamp3 (Bedside Lamp D2) with full colour and 1700-6500K CT range (fixes cellcortex#144)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I kept running into an issue where my bulbs would go permanently offline and the only fix was restarting the plugin. The logs
would fill up with:
Socket Closed with error "Error, retrying to connect in 5s" connect ETIMEDOUT 169.254.118.86:55443
After digging into the socket code I found a few issues causing this:
The main one: when a bulb is power cycled it sends a graceful TCP FIN, which fires the end event rather than error. The
socketClosed handler only scheduled a reconnect when called with an error — a graceful close just disconnected and never tried
again, leaving the device permanently offline.
Other issues I fixed while I was in there:
connecting
never cleaned up
After this change bulbs reconnect automatically after a power cycle with no plugin restart needed.
Closes #69 (repeated socket errors flooding logs — fixed by proper reconnect on graceful close and orphaned socket cleanup)
Closes #116 (UnhandledPromiseRejection — fixed by rejecting pending transactions on disconnect)
Closes #157 (Smart Light Panels colour not working — added plate2 spec)
May fix #86 (CT slider no effect — stale transactions were silently dropping CT commands)
May fix #112, #144 (Adaptive Lighting — stale transactions and 50hr floodAlarm suspension)
May fix #154, #155, #156 (post-update regressions — floodAlarm and stale transaction fixes)