session: track app session closes 03/38303/2
authorFlorin Coras <fcoras@cisco.com>
Mon, 20 Feb 2023 23:14:04 +0000 (15:14 -0800)
committerFlorin Coras <fcoras@cisco.com>
Tue, 21 Feb 2023 02:17:52 +0000 (18:17 -0800)
Make sure applications, especially builtin ones, cannot close a session
multiple times.

Type: improvement

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I960a1ae89a48eb359e7e1873a59d47c298c37ef1

src/vnet/session/session.c
src/vnet/session/session_types.h

index eaba80f..b0dbb9d 100644 (file)
@@ -1526,9 +1526,15 @@ session_half_close (session_t *s)
 void
 session_close (session_t * s)
 {
-  if (!s)
+  if (!s || (s->flags & SESSION_F_APP_CLOSED))
     return;
 
+  /* Transports can close and delete their state independent of app closes
+   * and transport initiated state transitions can hide app closes. Instead
+   * of extending the state machine to support separate tracking of app and
+   * transport initiated closes, use a flag. */
+  s->flags |= SESSION_F_APP_CLOSED;
+
   if (s->session_state >= SESSION_STATE_CLOSING)
     {
       /* Session will only be removed once both app and transport
index dcbbd72..513929a 100644 (file)
@@ -173,7 +173,8 @@ typedef enum
   _ (IS_MIGRATING, "migrating")                                               \
   _ (UNIDIRECTIONAL, "unidirectional")                                        \
   _ (CUSTOM_FIFO_TUNING, "custom-fifo-tuning")                                \
-  _ (HALF_OPEN, "half-open")
+  _ (HALF_OPEN, "half-open")                                                  \
+  _ (APP_CLOSED, "app-closed")
 
 typedef enum session_flags_bits_
 {