Skip to content

Replace add_reader/add_writer with async socket ops for Windows compatibility#376

Merged
pavel-kirienko merged 6 commits intov2from
copilot/make-udp-transport-windows-compatible
Mar 19, 2026
Merged

Replace add_reader/add_writer with async socket ops for Windows compatibility#376
pavel-kirienko merged 6 commits intov2from
copilot/make-udp-transport-windows-compatible

Conversation

Copy link

Copilot AI commented Mar 18, 2026

UDPTransport used loop.add_reader()/add_writer() which are not supported on Windows' ProactorEventLoop.

Changes

  • RX path: Replace add_reader callbacks with asyncio.Task loops using loop.sock_recvfrom() (Python 3.11+). Tasks tracked in _unicast_rx_tasks and _mcast_rx_tasks for lifecycle management.
  • TX path: Replace manual add_writer/remove_writer writability-wait in _async_sendto with loop.sock_sendto().
  • Cleanup: close() and _UDPSubjectListener.close() cancel tasks instead of calling remove_reader().
  • Tests: Remove _SKIP_WINDOWS marker from all integration test classes.

Before:

# Event-driven (SelectorEventLoop only)
self._loop.add_reader(sock.fileno(), self._on_unicast_data, i)

After:

# Cross-platform async task
task = self._loop.create_task(self._unicast_rx_loop(sock, i))
self._unicast_rx_tasks.append(task)

Added asyncio.sleep(0.1) backoff in RX loops on persistent OSError to avoid tight-looping (the old add_reader approach was inherently event-gated).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 239.0.0.10
    • Triggering command: REDACTED, pid is -1 (packet block)
  • 239.0.0.100
    • Triggering command: REDACTED, pid is -1 (packet block)
  • 239.0.0.42
    • Triggering command: REDACTED, pid is -1 (packet block)
  • 239.0.0.50
    • Triggering command: REDACTED, pid is -1 (packet block)
  • 239.0.0.55
    • Triggering command: REDACTED, pid is -1 (packet block)
  • 239.0.0.60
    • Triggering command: REDACTED, pid is -1 (packet block)
  • 239.0.0.7
    • Triggering command: REDACTED, pid is -1 (packet block)
  • 239.0.0.70
    • Triggering command: REDACTED, pid is -1 (packet block)
  • 239.0.0.80
    • Triggering command: REDACTED, pid is -1 (packet block)
  • 239.0.0.99
    • Triggering command: REDACTED, pid is -1 (packet block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI and others added 2 commits March 18, 2026 23:00
…tibility

Replace loop.add_reader()/remove_reader() with async recv loop tasks
using loop.sock_recvfrom() for both unicast and multicast sockets.

Replace loop.add_writer()/remove_writer() in _async_sendto with
loop.sock_sendto().

These asyncio socket methods work on all platforms including Windows'
ProactorEventLoop, which does not support add_reader/add_writer.

Remove _SKIP_WINDOWS markers from integration tests.

Co-authored-by: pavel-kirienko <3298404+pavel-kirienko@users.noreply.github.com>
Co-authored-by: pavel-kirienko <3298404+pavel-kirienko@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix UDPTransport for Windows compatibility Replace add_reader/add_writer with async socket ops for Windows compatibility Mar 18, 2026
Copilot AI requested a review from pavel-kirienko March 18, 2026 23:02
@pavel-kirienko pavel-kirienko marked this pull request as ready for review March 19, 2026 10:42
pavel-kirienko and others added 3 commits March 19, 2026 13:02
On Windows (ProactorEventLoop), loop.sock_sendto() doesn't go through
socket.socket.sendto, so patching the latter had no effect. Mock at the
event loop level instead, which works cross-platform.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pavel-kirienko pavel-kirienko merged commit 70ad49f into v2 Mar 19, 2026
22 checks passed
@pavel-kirienko pavel-kirienko deleted the copilot/make-udp-transport-windows-compatible branch March 19, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants