cederom commented on PR #22440: URL: https://github.com/apache/nuttx/pull/22440#issuecomment-7247722930
Thanks, this closes the old `REVISIT` in `tcp_backlogfree()` nicely. I traced the new path and it looks correct to me: - The RST goes out from `tcp_poll()` → `tcp_close_abort_eventhandler()` → `tcp_appsend()` (`TCP_ABORT` → `TCP_RST | TCP_ACK`, state `TCP_CLOSED`), with the connection lock held, and the free is deferred to the existing `tcp_close_work()`, which already re-checks `crefs == 0 && TCP_CLOSED` under the device lock. `TCP_CLOSE_ARRANGED` keeps `tcp_free()`/`tcp_reclaim()` consistent with the queued work. - The state check (`ESTABLISHED` / `CLOSE_WAIT`) matches exactly the states in which `tcp_poll()` delivers `TCP_POLL`, so the callback can't be left waiting for a poll that never comes in those states. Pending connections can't be in any other sending state (no socket ever sent a FIN), so the "free at once" branch is effectively only hit for `TCP_CLOSED` (peer RST between `tcp_backlogdetach()` and `tcp_close_abort()`) or `dev == NULL`. - A RST from the peer, a keepalive timeout or `NETDEV_DOWN` while the abort is pending is handled via `TCP_DISCONN_EVENTS` → `TCP_CLOSED` → `tcp_close_work()` frees it. Data arriving in the meantime gets the RST in the input path (`TCP_NEWDATA`/`TCP_ACKDATA` are in the mask). Good. - The new connection isn't reclaimable by `tcp_reclaim()` while it waits (ESTABLISHED/CLOSE_WAIT is not in `tcp_reclaimable()`), and becomes reclaimable once `TCP_CLOSED` + `TCP_CLOSE_ARRANGED`. Fine. - All `tcp_free()` callers that can reach a listener with a backlog run in task context (`tcp_close_disconnect()`, `tcp_close_work()` on LPWORK, `tcp_backlogcreate()`), so the "no network lock held" assumption holds. Minor comments, none blocking: 1. **Callback allocation failure.** If `tcp_callback_alloc()` fails, the connection is freed silently, as before. `tcp_close_disconnect()` retries after `tcp_reclaim(NULL)` in the same situation. It would be consistent (and cheap) to do the same here, or at least `nwarn()` that the peer won't get a RST. 2. **Device down at the time of the close.** If `dev != NULL` but the interface is already down, no poll and no further `NETDEV_DOWN` event will come until it is brought up again. So the connection and its callback stay allocated for as long as the interface is down, and the RST is sent when it comes back. `close()` of a normal socket behaves the same way, so this is consistent. But for a connection that no socket will ever own, freeing at once when `!IFF_IS_UP(dev->d_flags)` seems simpler. Your call. 3. **Docs wording.** In `tcp_state_machine.rst`, "as on Linux" is followed by the `listen()`-shrink sentence, which can read as if Linux also resets there. Linux resets the pending children on close (`inet_csk_listen_stop()`), but `listen()` with a smaller backlog only lowers `sk_max_ack_backlog` and keeps the connections already queued. Maybe say explicitly that the shrink behaviour is NuttX-specific (it already dropped those connections before this PR, so now they just get a RST instead of silence). The commit message already gets this right. LGTM with or without these. -- 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]
