cederom commented on PR #22145:
URL: https://github.com/apache/nuttx/pull/22145#issuecomment-7120270084
The branch was rebased onto newer master. Two commits are unchanged, and the
device-file line count only got a new hash. The rest changed:
- **`/proc/net/tcp` and `udp` (was medium #1): fixed.** Each connection now
gets a list number, from a counter that only grows, when it joins the active
list. The reader remembers the number of the last line it wrote, not a count
from the head. So a connection that is freed no longer shifts the reader's
place, and a connection that arrives after the first read is left out, so the
read still ends.
- I checked the two things this depends on. The only places that add to
either list are `tcp_add_active_conn()` and `udp_alloc()`, and both add at the
tail with the next number. Nothing else assigns `conn->dev` once a connection
is in the list: there is a `DEBUGASSERT` that it stays NULL or the same in the
connect event handler, and the `tcp_monitor.c` assignment is `#if 0`.
- The number comparison handles counter wrap-around.
- **Line skipped after three failed tries (was #2): removed.** After waiting
for the device lock, the walk now writes that connection's line, or finds it
has gone.
- **Output format change (was #4):** now stated in the commit message.
- **Destroyed lock in `tcp_free()` (was #5): fixed.** The backlog is now
detached before `conn_uninit()`.
- **`tcp_remove_syn_backlog()` loop (was #6): fixed.** It frees only
connections numbered at or before the point where the listener left the table,
so a new listener on the same port is not touched and the loop ends.
- **Lock rule for the accept handler (was #7): documented** in `tcp.h`, at
the `accept` field and at `tcp_accept_connection()`.
Still open:
1. **UDP still formats lines without the device lock (was #3).** It reads
`readahead` and calls `udp_wrbuffer_inqueue_size()` without it, and no commit
message mentions this. A note in the PR saying UDP is left for later would be
enough.
2. **Nit:** `TCP_LISTID_AFTER` and `UDP_LISTID_AFTER` are the same macro and
could be one in `net/utils/utils.h`.
3. **Nit, already in master:** the UDP header shows the `txsz` column under
`CONFIG_NET_SEND_BUFSIZE > 0`, but each line prints it under
`CONFIG_NET_UDP_WRITE_BUFFERS`, so the columns can be misaligned. TCP already
has the matching condition.
4. **Already in master, a possible follow-up:** `tcp_removeconn()` removes a
connection from the active list with no list lock. Its only caller is the
connect event handler, which holds only the device lock. That can corrupt the
list while the procfs walk or `tcp_remove_syn_backlog()` is going through it.
It's outside this PR, but it is the same kind of locking problem the series
fixes.
--
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]