Skip to content

ws2_offline: let connect dissolve a UDP association (WS2-UDP-DISCONNECT) - #2241

Draft
syfyra wants to merge 2 commits into
ProjectLeonida:mainfrom
syfyra:fix/ws2-udp-disconnect
Draft

syfyra wants to merge 2 commits into
ProjectLeonida:mainfrom
syfyra:fix/ws2-udp-disconnect

Conversation

@syfyra

@syfyra syfyra commented Nov 26, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as: WS2-UDP-DISCONNECT (claim comment to follow)

What and why

runtime/shims/ws2_offline.cpp lets connect and WSAConnect through only for loopback addresses and fails everything else with WSAENETUNREACH. connect's remarks give an all-zero address a second meaning on a connectionless socket: it dissolves the association, after which send/recv fail with WSAENOTCONN and datagrams from any address arrive again. The shim refused that address like any external one, so a UDP socket connected once to a loopback peer stayed tied to it: the title's disconnect failed, and datagrams from every other loopback port kept being dropped.

Measured with a small probe on Windows 11 (loopback only):

call UDP socket connected to 127.0.0.1:A TCP socket
connect(0.0.0.0:0) 0, association gone (getpeername → WSAENOTCONN) WSAEADDRNOTAVAIL
connect([::]:0) (IPv6 socket) 0, association gone WSAEADDRNOTAVAIL ([::]:80)
connect(AF_UNSPEC) 0, association gone WSAEAFNOSUPPORT
WSAConnect(0.0.0.0:0) 0, association gone
connect(0.0.0.0:4321) WSAEADDRNOTAVAIL, still connected WSAEADDRNOTAVAIL

None of these reaches a peer. connect and WSAConnect now pass the disconnect forms (an AF_UNSPEC address, and 0.0.0.0 or :: with port 0) to the host. 0.0.0.0 with a port stays refused before the host, as before.

Tested

Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo:

  • ws2_offline_test gets a section 5b: a loopback UDP socket connected to A is disconnected with connect(0.0.0.0:0), after which getpeername and send fail with WSAENOTCONN and a datagram from a second socket B arrives; the same through WSAConnect and with an AF_UNSPEC address and, on an IPv6 socket, with [::]:0. 0.0.0.0:4321 stays refused with WSAENETUNREACH, and on a TCP socket both forms fail with the host's error.
    • main: 9 of the 12 new checks fail.
    • this branch: 83 of 83 checks pass, in 3 of 3 runs.
  • ctest -j 8 over the 168 CPU tests, with this branch and WS2-CONNECT-BY-NAME-V6 merged: all pass except xmem_no_write_watch, whose split-reader check is the start race runtime tests: race a reader thread only once it reads (RT-TESTS-READER-START) #2131 fixes (it passes on its own).
  • scripts/check_no_game_data.py on both files.

Not tested under Wine.

This and WS2-CONNECT-BY-NAME-V6 both change ws2_offline.cpp and its test, in different places; they merge cleanly in either order.

GPUs tested: n/a (CPU tests)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

connect's remarks: on a connectionless socket, connecting to an all-zero
address dissolves the association, after which send and recv fail with
WSAENOTCONN. connect and WSAConnect refused that address as a
non-loopback destination (WSAENETUNREACH), so a datagram socket stayed
tied to its first peer for good: datagrams from any other address were
still dropped.

Windows 11 dissolves the association for 0.0.0.0:0, [::]:0 and an
AF_UNSPEC address and refuses 0.0.0.0 with a port (WSAEADDRNOTAVAIL); a
TCP socket refuses all of them. None reaches a peer, so those forms now
go to the host; 0.0.0.0 with a port stays refused before it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built ws2_offline_test at this head with MSVC on Windows 11. CTest passed with 83 checks and zero failures, including the new UDP association teardown and reconnect coverage. No findings from these checks.

AI-assisted.

The Winsock2 section still described the shim before this change; it now names the new behaviour and the test that covers it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@syfyra

syfyra commented Nov 26, 2026

Copy link
Copy Markdown
Author

Follow-up commit 1c6f552: the Winsock2 section of docs/runtime_imports.md still described the shim before this change. It now has a bullet for the two disconnect forms connect and WSAConnect pass (an AF_UNSPEC address, and 0.0.0.0 or :: with port 0), and its test summary names the new check. Docs only; tests/test_docs_links.py and tests/test_docs_cli_flags.py pass. It merges cleanly with #2242 and #2341, which edit the same section on other lines.

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