fix(libkernel): refuse a reconnect after a dropped connection on macOS #17879

Merged
Alexius0815 merged 1 commit from upstream-pr/17879 into main 2026-12-03 16:42:45 +00:00
Alexius0815 commented 2026-11-09 20:08:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Alexius0815 on 2026-11-09T20:08:55Z.


What

On macOS, retrying connect after a refused nonblocking TCP connection returns EISCONN (56). guest_socket_options expects ECONNREFUSED (61). #14183 addressed the Windows behavior for this test.

For Darwin IPv4 and IPv6 stream sockets, the change queries TCP_CONNECTION_INFO after an EISCONN result. It returns ECONNREFUSED when the query succeeds, the response covers the state field, and that field is TCPS_CLOSED. Every other result preserves the original connect error. Unix-domain sockets bypass the query.

In FreeBSD 11.4, the IPv4 tcp_usr_connect path returns ECONNREFUSED for an INP_DROPPED PCB. INP_TIMEWAIT takes a separate EADDRINUSE branch. The Darwin patch leaves the native EISCONN result unchanged in the tested TIME_WAIT case.

Tested

Apple M4 (Mac16,13), macOS 27.2, Release x86-64 under Rosetta 2. CTest ran serially with the final v4 diffs on Mac integration stack b05b1c4c93a2 (main 02452319 with Mac build fixes). The review commit is based on main 7259cce111.

  • Baseline: guest_socket_options aborts with errno 56 at the refused-connect retry check.
  • TCP-only arm: guest_socket_options passes. The separate guest_socket_port_zero failure remains.
  • Combined UDP and TCP arm: 95 of 97 socket and network tests pass, one is skipped (guest_net_raw_protocol), and guest_sce_net hits the known epoll closed-stream failure.

A separate native Darwin probe checked the state query and its returned length. Refusal and peer reset produced CLOSED. The live, peer FIN, and local-close-first controls produced ESTABLISHED, CLOSE_WAIT, and TIME_WAIT respectively. The TCP option query returned EOPNOTSUPP for Unix-domain sockets. These controls are native probe results. Guest coverage is the refused-connect case in guest_socket_options.

Checklist

  • Based on current main; no other open PR implements the same change
  • One topic per PR
  • No comments added to source code
  • No new stubs or third-party code
  • No investigation files added to the repository
  • Generic behavior, independent of title
  • Depends on: none
  • Fixes: none
  • Unblocks: none known
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5230406543 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17879). Originally posted by [Alexius0815](https://github.com/Alexius0815) on 2026-11-09T20:08:55Z. --- ### What On macOS, retrying `connect` after a refused nonblocking TCP connection returns `EISCONN` (56). `guest_socket_options` expects `ECONNREFUSED` (61). #14183 addressed the Windows behavior for this test. For Darwin IPv4 and IPv6 stream sockets, the change queries `TCP_CONNECTION_INFO` after an `EISCONN` result. It returns `ECONNREFUSED` when the query succeeds, the response covers the state field, and that field is `TCPS_CLOSED`. Every other result preserves the original `connect` error. Unix-domain sockets bypass the query. In FreeBSD 11.4, the IPv4 `tcp_usr_connect` path returns `ECONNREFUSED` for an `INP_DROPPED` PCB. `INP_TIMEWAIT` takes a separate `EADDRINUSE` branch. The Darwin patch leaves the native `EISCONN` result unchanged in the tested TIME_WAIT case. ### Tested Apple M4 (Mac16,13), macOS 27.2, Release x86-64 under Rosetta 2. CTest ran serially with the final v4 diffs on Mac integration stack `b05b1c4c93a2` (main `02452319` with Mac build fixes). The review commit is based on main `7259cce111`. - Baseline: `guest_socket_options` aborts with errno 56 at the refused-connect retry check. - TCP-only arm: `guest_socket_options` passes. The separate `guest_socket_port_zero` failure remains. - Combined UDP and TCP arm: 95 of 97 socket and network tests pass, one is skipped (`guest_net_raw_protocol`), and `guest_sce_net` hits the known epoll closed-stream failure. A separate native Darwin probe checked the state query and its returned length. Refusal and peer reset produced `CLOSED`. The live, peer FIN, and local-close-first controls produced `ESTABLISHED`, `CLOSE_WAIT`, and `TIME_WAIT` respectively. The TCP option query returned `EOPNOTSUPP` for Unix-domain sockets. These controls are native probe results. Guest coverage is the refused-connect case in `guest_socket_options`. ### Checklist - [x] Based on current `main`; no other open PR implements the same change - [x] One topic per PR - [x] No comments added to source code - [x] No new stubs or third-party code - [x] No investigation files added to the repository - [x] Generic behavior, independent of title - Depends on: none - Fixes: none - Unblocks: none known - GPUs tested: n/a - AI-assisted: yes
kurexw commented 2026-11-16 12:13:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-16T12:13:43Z.

Review: COMMENTED


Tested on macOS 27.2, Apple Silicon (M4), full build (x86-64 under Rosetta 2). This PR was merged alone onto main 04f7633c01 with git merge --no-ff. I ran the 56 socket and net tests (guest_socket_*, guest_poll, guest_refused_connect, guest_sce_net, guest_net_*, guest_kernel_socket*) three times on main and three times with this PR.

  • guest_socket_options fails in all three runs on main ("a connect after a refused nonblocking one must fail with ECONNREFUSED (61), not start another attempt (errno 56)") and passes in all three runs with this PR.
  • No other test changes.
  • This PR and #17878 conflict in core/libs/prx/libkernel/Socket/src/Udp.cpp, so whichever merges second needs a rebase.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5919768553 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17879#pullrequestreview-5919768553). Originally posted by [kurexw](https://github.com/kurexw) on 2026-11-16T12:13:43Z. **Review:** COMMENTED --- Tested on macOS 27.2, Apple Silicon (M4), full build (x86-64 under Rosetta 2). This PR was merged alone onto `main` 04f7633c01 with `git merge --no-ff`. I ran the 56 socket and net tests (`guest_socket_*`, `guest_poll`, `guest_refused_connect`, `guest_sce_net`, `guest_net_*`, `guest_kernel_socket*`) three times on `main` and three times with this PR. - `guest_socket_options` fails in all three runs on `main` ("a connect after a refused nonblocking one must fail with ECONNREFUSED (61), not start another attempt (errno 56)") and passes in all three runs with this PR. - No other test changes. - This PR and #17878 conflict in `core/libs/prx/libkernel/Socket/src/Udp.cpp`, so whichever merges second needs a rebase.
MarcZX10 commented 2026-11-22 08:45:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T08:45:51Z.

Review: APPROVED


Reviewed — looks good

The reviewed change at a9af1f20373d9b8606bd42805d4dff0a50bfafee has no verified blocking defects; the description reports targeted native Darwin controls and guest coverage, which I did not run.

What I ran

No commands or tests were run. I inspected the prepared diff and the changed source at the pinned head.

Results

Check Result Note
Diff and changed source passed One changed file inspected
Tests not run Author-reported results only

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run tests or independently verify the reported macOS probes and integration results. files.json was not available in the review bundle, but the manifest lists one reviewed file, and its full source was read. No files were excluded according to the manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6011332702 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17879#pullrequestreview-6011332702). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T08:45:51Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change at `a9af1f20373d9b8606bd42805d4dff0a50bfafee` has no verified blocking defects; the description reports targeted native Darwin controls and guest coverage, which I did not run. ## What I ran No commands or tests were run. I inspected the prepared diff and the changed source at the pinned head. ## Results | Check | Result | Note | |---|---|---| | Diff and changed source | passed | One changed file inspected | | Tests | not run | Author-reported results only | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not run tests or independently verify the reported macOS probes and integration results. `files.json` was not available in the review bundle, but the manifest lists one reviewed file, and its full source was read. No files were excluded according to the manifest. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 16:40:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T16:40:38Z.

Review: COMMENTED


With this revision integrated on Linux, guest_socket_options passed and the multicast variant was skipped. The Darwin code checks the TCP_CONNECTION_INFO result and returned length before reading tcpi_state, and preserves errno across the probe. The Darwin reconnect path still needs verification on macOS.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6174140688 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17879#pullrequestreview-6174140688). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T16:40:38Z. **Review:** COMMENTED --- With this revision integrated on Linux, `guest_socket_options` passed and the multicast variant was skipped. The Darwin code checks the `TCP_CONNECTION_INFO` result and returned length before reading `tcpi_state`, and preserves errno across the probe. The Darwin reconnect path still needs verification on macOS. AI-assisted: yes.
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
boykopovar/AnyPS5!17879
No description provided.