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

Closed
syfyra wants to merge 2 commits from upstream-pr/2241 into main
syfyra commented 2026-11-26 10:10:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by syfyra on 2026-11-26T10:10:19Z.


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 #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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5508031636 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2241). Originally posted by [syfyra](https://github.com/syfyra) on 2026-11-26T10:10:19Z. --- 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 #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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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](https://claude.com/claude-code)
lixonik commented 2026-11-26 10:58:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T10:58:25Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6072924240 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2241#pullrequestreview-6072924240). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T10:58:25Z. **Review:** COMMENTED --- 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.
syfyra commented 2026-11-26 14:32:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by syfyra on 2026-11-26T14:32:35Z.


Follow-up commit 1c6f552cc: 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7194969882 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2241#issuecomment-7194969882). Originally posted by [syfyra](https://github.com/syfyra) on 2026-11-26T14:32:35Z. --- Follow-up commit 1c6f552cc: 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.
fiestorra commented 2026-11-30 10:32:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T10:32:15Z.


Independent verification on this machine (Windows 11, MSVC 19.44.35226), with a negative control that bites on two assertions.

1. It applies. merge-tree clean; the commits cherry-pick onto main 012b79a67 without a conflict. Two files: runtime/shims/ws2_offline.cpp and runtime/test/ws2_offline_test.cpp.

2. With the branch its test passes:

ctest -R 'ws2_offline'
100% tests passed, 0 tests failed out of 1

3. The control - revert only the shim, keep the test:

git checkout origin/main -- runtime/shims/ws2_offline.cpp
cmake --build … --target ws2_offline_test
ctest -R 'ws2_offline' --output-on-failure
0% tests passed, 1 tests failed out of 1
FAIL connect to 0.0.0.0:0 succeeds on a connected UDP socket
FAIL after it getpeername fails with WSAENOTCONN

The two failures describe the change exactly: a connect to 0.0.0.0:0 on a connected UDP socket must succeed (it is a null address the Winsock layer accepts), and once it has, getpeername must fail with WSAENOTCONN because the socket is not connected to a peer. The branch's shim implements that pair; main's does not.

What I did not test: the rest of the offline Winsock surface, and whether 0.0.0.0:0 behaves the same on the console's stack - this is measured against the title's real API only as far as the shim models it.

Why I am commenting: I verify open pull requests that replay onto current main, then revert only the source change and re-run to see which tests stop passing. 17 controls so far; 12 bite.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7275734894 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2241#issuecomment-7275734894). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-30T10:32:15Z. --- Independent verification on this machine (Windows 11, MSVC 19.44.35226), with a negative control that bites on two assertions. **1. It applies.** `merge-tree` clean; the commits cherry-pick onto `main` `012b79a67` without a conflict. Two files: `runtime/shims/ws2_offline.cpp` and `runtime/test/ws2_offline_test.cpp`. **2. With the branch its test passes:** ``` ctest -R 'ws2_offline' 100% tests passed, 0 tests failed out of 1 ``` **3. The control - revert only the shim, keep the test:** ``` git checkout origin/main -- runtime/shims/ws2_offline.cpp cmake --build … --target ws2_offline_test ctest -R 'ws2_offline' --output-on-failure 0% tests passed, 1 tests failed out of 1 FAIL connect to 0.0.0.0:0 succeeds on a connected UDP socket FAIL after it getpeername fails with WSAENOTCONN ``` **The two failures describe the change exactly**: a `connect` to `0.0.0.0:0` on a connected UDP socket must **succeed** (it is a null address the Winsock layer accepts), and once it has, `getpeername` must fail with `WSAENOTCONN` because the socket is not connected to a peer. **The branch's shim implements that pair; `main`'s does not.** **What I did not test:** the rest of the offline Winsock surface, and whether `0.0.0.0:0` behaves the same on the console's stack - **this is measured against the title's real API only as far as the shim models it**. **Why I am commenting:** I verify open pull requests that replay onto current `main`, then revert **only** the source change and re-run to see which tests stop passing. **17 controls so far; 12 bite.** Written with an AI assistant.
aslan2142 commented 2026-12-01 12:27:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:27:12Z.


Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.

(AI-assisted triage.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7311152429 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2241#issuecomment-7311152429). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:27:12Z. --- Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review. *(AI-assisted triage.)*
aslan2142 commented 2026-12-01 16:43:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:43:18Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7318102068 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2241#issuecomment-7318102068). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:43:18Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2241
No description provided.