You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/07/04 13:54:23 UTC

[incubator-nuttx] branch master updated: Attempt to fix race condition reported in issue #3647

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

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


The following commit(s) were added to refs/heads/master by this push:
     new a885b24  Attempt to fix race condition reported in issue #3647
a885b24 is described below

commit a885b24cc1bbb9a97230da0820843981839ca01a
Author: Anthony Merlino <an...@vergeaero.com>
AuthorDate: Mon May 3 13:01:31 2021 -0400

    Attempt to fix race condition reported in issue #3647
---
 net/tcp/tcp_send_unbuffered.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c
index 64e41a1..d487318 100644
--- a/net/tcp/tcp_send_unbuffered.c
+++ b/net/tcp/tcp_send_unbuffered.c
@@ -538,9 +538,12 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
       goto errout;
     }
 
-  /* If this is an un-connected socket, then return ENOTCONN */
+  /* Check early if this is an un-connected socket, if so, then
+   * return -ENOTCONN. Note, we will have to check this again, as we can't
+   * guarantee the state won't change until we have the network locked.
+   */
 
-  if (psock->s_type != SOCK_STREAM || !_SS_ISCONNECTED(psock->s_flags))
+  if (psock->s_type != SOCK_STREAM)
     {
       nerr("ERROR: Not connected\n");
       ret = -ENOTCONN;
@@ -593,6 +596,19 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
    */
 
   net_lock();
+
+  /* Now that we have the network locked, we need to check the connection
+   * state again to ensure the connection is still valid.
+   */
+
+  if (!_SS_ISCONNECTED(psock->s_flags))
+    {
+      nerr("ERROR: No longer connected\n");
+      net_unlock();
+      ret = -ENOTCONN;
+      goto errout;
+    }
+
   memset(&state, 0, sizeof(struct send_s));
 
   /* This semaphore is used for signaling and, hence, should not have