casaroli opened a new pull request, #22440:
URL: https://github.com/apache/nuttx/pull/22440

   ## Summary
   
   When a listener closes, or `listen()` again makes its backlog smaller, 
`tcp_backlogfree()` freed each pending connection without a segment to the peer 
(`REVISIT -- such connections really need to be gracefully closed`). The peer 
stays in ESTABLISHED (or in FIN_WAIT_2 if it already closed its socket) and 
learns nothing until it sends data. A client that waits for the answer of the 
server waits for ever.
   
   Now `tcp_close_abort()` ends a connection that no socket refers to with a 
RST at the next poll of its device, and then frees it. A connection in another 
state than ESTABLISHED or CLOSE_WAIT, or without a device, is freed at once, as 
before. The backlog uses it for each pending connection. Linux also resets the 
pending connections when a listener closes (`inet_csk_listen_stop()`).
   
   The new close callback does not reuse `tcp_close_eventhandler()`: that one 
sends a FIN and waits for its ACK unless data is unread or `SO_LINGER` is 0, 
and a pending connection that no socket will read must get a RST at once.
   
   Commit 2 adds one paragraph to 
`Documentation/os/networking/tcp_state_machine.rst`.
   
   ## Impact
   
   The peer of a connection that waits in the backlog of a closed listener gets 
a RST (before: nothing). No API, ABI or Kconfig change. Common network code: 
the same in flat, protected and kernel builds and on all architectures. Size: 
+324 bytes of text on qemu-armv8a:knsh (kernel image).
   
   ## Testing
   
   New case `test_tcp_backlog_close_reset` in `cmocka_net_tcp` 
(apache/nuttx-apps#NNNN): two clients connect to a listener of backlog 4 and 
nobody accepts them; the listener closes; `recv()` of each client must give 
`ECONNRESET` within 3 s (`SO_RCVTIMEO`). 3 rounds.
   
   | qemu-armv8a:nsh (flat), QEMU TCG, CI image (gcc 12.3) | master 24f2db7fe8d 
| this PR |
   |---|---|---|
   | `test_tcp_backlog_close_reset`, 3 boots | FAIL 3 of 3: `recv()` gives 
`EAGAIN` after 3 s (`11 != 104`) | PASS 3 of 3 |
   | the 4 `test_tcp_backlog_*` cases (with the existing race cases), 3 boots, 
32 TCP connections | `close_reset` FAILS 3 of 3, the other 3 pass | 4 of 4 
pass, 3 of 3 |
   
   Whole `cmocka_net_tcp` (1 boot each, `CONFIG_NET_TCP_PREALLOC_CONNS=32`, 
with the cases of this PR and of the TCP_CORK PR #NNNNN): master fails 
`test_tcp_cork`, `test_tcp_backlog_close_reset` and `test_tcp_reset_send`; with 
the fixes only `test_tcp_reset_send` fails (37 of 38 pass). 
`test_tcp_reset_send` fails on master too in a flat build (`SIGPIPE` goes to 
another thread). With the default 8 connections the race cases of the same file 
can fail on both sides with `socket()` errors: the earlier cases leave 
connections in TIME_WAIT.
   
   Builds with `-Werror` in the CI image (gcc 12.3): qemu-armv8a:nsh (flat, 
with `cmocka_net_tcp`) and qemu-armv8a:knsh (kernel), rv-virt:netnsh64 (flat, 
with `cmocka_net_tcp`) and rv-virt:knetnsh64 (kernel); no new warning. 
Protected build: not built (common network code, no build-mode test).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] net/tcp: Reset the pendi... casaroli (via GitHub) via commits

Reply via email to