Platform: Windows 10 64-bit
Python version: 3.9.10
Problem: Under Windows, the UDP broadcast socket is closed asynchronously and may not be closed by the time a second discovery is initiated. This occurs even though the SO_REUSEADDR socket option is specified. This appears to be unique to Windows - Linux-based environments operate normally.
Observed output:
Traceback (most recent call last):
File "demo.py", line 48, in <module>
main_loop.run_until_complete(main())
File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
return future.result()
File "demo.py", line 44, in main
await discovery.discover_lights()
File "\pywizlight\discovery.py", line 129, in discover_lights
discovered_IPs = await find_wizlights(broadcast_address=broadcast_space)
File "\pywizlight\discovery.py", line 111, in find_wizlights
transport, protocol = await loop.create_datagram_endpoint(
File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 1363, in create_datagram_endpoint
raise exceptions[0]
File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 1347, in create_datagram_endpoint
sock.bind(local_address)
OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
Platform: Windows 10 64-bit Python version: 3.9.10
Problem: Under Windows, the UDP broadcast socket is closed asynchronously and may not be closed by the time a second discovery is initiated. This occurs even though the SO_REUSEADDR socket option is specified. This appears to be unique to Windows - Linux-based environments operate normally.
Observed output:
Steps to reproduce this:
Proposed fix: Wait for Protocol::connection_lost() to be invoked before considering the socket closed