Sarthak-Pandey opened a new pull request, #22070:
URL: https://github.com/apache/nuttx/pull/22070

   ## Summary
   
   Fixes #22050: net/tcp: IOB exhaustion and TCP receive window 
oversubscription with multiple active sockets.
   
   ### Why the change is necessary?
   Previously, `tcp_get_recvwindow()` calculated the advertised TCP receive 
window (`recvwndo`) by assuming that the calling connection could utilize 100% 
of all remaining available IOBs in the system pool:
   ```c
   recvwndo = tailroom + (niob_avail * CONFIG_IOB_BUFSIZE);
   ```
   In scenarios with multiple concurrent active TCP connections, every socket 
greedily advertised the entire free IOB capacity. When remote peers transmitted 
data concurrently, the global IOB pool was rapidly depleted. This led to:
   1. Allocation failures (`iob_tryalloc()` returning NULL).
   2. Dropped packets and aggressive TCP retransmission storms.
   3. Potential deadlocks where network workers or critical tasks waiting on 
`iob_alloc()` starved indefinitely.
   
   ### How the change works:
   In 
[net/tcp/tcp_recvwindow.c](file:///d:/OpenSource/Nuttux_All_Repo/nuttx/net/tcp/tcp_recvwindow.c):
   1. Traversed the active connection list using `tcp_nextconn()` to 
dynamically count the number of active TCP connections (`nconns`).
   2. Fairly partitioned the available IOBs among all active connections:
      ```c
      niob_per_conn = niob_avail / nconns;
      ```
   3. Advertised only this connection's fair share of IOB buffering in 
`recvwndo`, preventing multiple active sockets from oversubscribing the shared 
global pool.
   4. Preserved existing single-connection and throttled fallback behavior 
without requiring any Kconfig changes.
   
   Fixes #22050
   
   ---
   
   ## Impact
   
   * **Is new feature added? Is existing feature changed?**
     - Existing feature improved: TCP receive window calculation is now 
multi-socket aware and fairly partitions available IOBs.
   * **Impact on user:**
     - Prevents system freeze, packet drops, and IOB starvation when running 
multiple simultaneous TCP sockets (e.g. HTTP server + MQTT + NTP).
   * **Impact on build:**
     - NO (Standard build process unchanged).
   * **Impact on hardware:**
     - NO (Hardware-agnostic, purely in the network L4 TCP layer).
   * **Impact on documentation:**
     - NO.
   * **Impact on security:**
     - Enhances stability and prevents Denial of Service (DoS) caused by buffer 
pool exhaustion.
   * **Impact on compatibility:**
     - 100% backward compatible. No Kconfig changes required.
   
   ---
   
   ## Testing
   
   1. Verified coding style with `tools/nxstyle` on `net/tcp/tcp_recvwindow.c` 
(0 errors, 0 warnings).
   2. Code review verification:
      - Handled edge cases where `nconns == 0` (clamped to 1).
      - Handled edge cases where `niob_per_conn == 0` (clamped to 1 when 
`niob_avail > 0`).
      - Verified active connections are traversed safely using `tcp_nextconn()`.


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

Reply via email to