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

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

commit da5a493f58e0866b754e7cbec3810ce9cd1bdd32
Author: Marco Casaroli <[email protected]>
AuthorDate: Fri Nov 20 17:12:24 2026 +0100

    net/tcp: Do not lose the wakeup of a send that waits on the send limit.
    
    With CONFIG_NET_SEND_BUFSIZE > 0, psock_tcp_send() compares the queued
    bytes with the limit while it holds the device and connection locks, and
    then waits on snd_sem.  conn_dev_sem_timedwait() releases the locks
    before the wait.  tcp_sendbuffer_notify() posted snd_sem only when a
    thread already waited on it (count < 0).  When the ACKs that empty the
    write queue arrive between the release of the locks and the wait (for
    example on the work queue of a network driver that waited for the device
    lock), the post was lost.  If no other ACK came, the sender waited until
    its SO_SNDTIMEO time-out, or for ever.
    
    Post also when the count is 0.  A count that no sender waited for only
    makes a sender check the limit once more.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 net/tcp/tcp_send_buffered.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c
index 2b88be23384..e5d1fa2d84b 100644
--- a/net/tcp/tcp_send_buffered.c
+++ b/net/tcp/tcp_send_buffered.c
@@ -1770,8 +1770,13 @@ void tcp_sendbuffer_notify(FAR struct tcp_conn_s *conn)
 {
   int val = 0;
 
+  /* Post also when no thread waits yet: a sender can be between its check
+   * of the limit and its wait, with the locks released.  A count that no
+   * sender waited for only makes a sender check the limit once more.
+   */
+
   nxsem_get_value(&conn->snd_sem, &val);
-  if (val < 0)
+  if (val <= 0)
     {
       nxsem_post(&conn->snd_sem);
     }

Reply via email to