-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Hi there, firstly, as always, thanks for the efforts on this.
I recently integrated twinkly squares support via this lib to ledfx
https://github.com/LedFx/LedFx
For the limited access I had to a twinkly squares set up, it worked fine.
now it is out on in the wild, I think I see a few issues.
Its related to the ver3 support, which as I understand it, only supports a socket create / send / destroy on a per message basis, is there a way to use persistent sockets there that I have missed.
Secondly from our population I see an instance of
[WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
The copilot position on this, which would match my own expectations is
Title: Multiple device instances cause "Address already in use" errors due to ephemeral port exhaustion in realtime mode
Description:
When controlling multiple Twinkly devices simultaneously in realtime mode (RT mode), we encounter "Address already in use" socket errors after running for a short period.
Root Cause:
The UDPClient class in udp_client.py binds to an ephemeral port on each socket creation:
_handle.bind(("", 0)) # Line 51 in udp_client.py
When using set_rt_frame_socket() with version 3 protocol, the library creates a new UDP socket frequently (as noted in the code: "version 3, but not persistent sockets"). With multiple devices sending frames at 30-60 FPS, this causes:
Ephemeral port exhaustion - OS runs out of available ports
TIME_WAIT accumulation - Closed sockets remain in TIME_WAIT state
Race conditions - Multiple instances competing for ports