This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 5ea879d72d2ce4ffc57060b067065db2d848cec4
Author: raiden00pl <[email protected]>
AuthorDate: Fri Oct 9 09:19:51 2026 +0200

    net/tcp: reuse closing connections also with CONFIG_NET_SOLINGER.
    
    When the connection pool is empty, tcp_alloc() frees the oldest
    closing or TIME_WAIT connection, but only without
    CONFIG_NET_SOLINGER. The guard protected a close() that blocked
    waiting for the close callback. Since 0636c17a63 ("net/tcp: wave
    hands on background") close() returns at once also with SO_LINGER
    (it only sets the linger timeout), and tcp_free() cancels the pending
    close work and the timer.
    
    With CONFIG_NET_SOLINGER, a node that closes its connections first
    ran out of TCP connections once CONFIG_NET_TCP_PREALLOC_CONNS of them
    were in TIME_WAIT: socket() failed with ENOMEM until TIME_WAIT
    expired.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: raiden00pl <[email protected]>
---
 net/tcp/tcp_conn.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c
index 7ca596dceac..55d0c3b3c44 100644
--- a/net/tcp/tcp_conn.c
+++ b/net/tcp/tcp_conn.c
@@ -596,7 +596,6 @@ FAR struct tcp_conn_s *tcp_alloc(uint8_t domain)
 
   conn = NET_BUFPOOL_TRYALLOC(g_tcp_connections);
 
-#ifndef CONFIG_NET_SOLINGER
   /* Is the free list empty? */
 
   if (!conn)
@@ -649,13 +648,9 @@ FAR struct tcp_conn_s *tcp_alloc(uint8_t domain)
            * of active connections and release all resources held by the
            * connection.
            *
-           * REVISIT:  Could there be any higher level, socket interface
-           * that needs to be informed that we did this to them?
-           *
-           * Actually yes. When CONFIG_NET_SOLINGER is enabled there is a
-           * pending callback in netclose_disconnect waiting for getting
-           * woken up.  Otherwise there's the callback too, but no one is
-           * waiting for it.
+           * No socket refers to it any more (crefs == 0) and close()
+           * does not wait for the close callback, also not with
+           * SO_LINGER, so nobody needs to be informed.
            */
 
           tcp_free(conn);
@@ -670,7 +665,6 @@ FAR struct tcp_conn_s *tcp_alloc(uint8_t domain)
           conn = NET_BUFPOOL_TRYALLOC(g_tcp_connections);
         }
     }
-#endif
 
   tcp_conn_list_unlock();
 

Reply via email to