session: maintain old state on premature close

Type: fix

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I2ea821e0499a3874c4579f5480ea86f30ebe615f
diff --git a/src/vnet/session/session_input.c b/src/vnet/session/session_input.c
index 404ee8b..efc4f54 100644
--- a/src/vnet/session/session_input.c
+++ b/src/vnet/session/session_input.c
@@ -77,7 +77,8 @@
 {
   application_t *app = application_get (app_wrk->app_index);
   svm_msg_q_t *mq = app_wrk->event_queue;
-  u8 ring_index, mq_is_cong, was_closed;
+  u8 ring_index, mq_is_cong;
+  session_state_t old_state;
   session_event_t *evt;
   u32 n_evts = 128, i;
   session_t *s;
@@ -148,7 +149,7 @@
 	  break;
 	case SESSION_CTRL_EVT_ACCEPTED:
 	  s = session_get (evt->session_index, thread_index);
-	  was_closed = s->session_state >= SESSION_STATE_TRANSPORT_CLOSING;
+	  old_state = s->session_state;
 	  if (app->cb_fns.session_accept_callback (s))
 	    {
 	      session_close (s);
@@ -162,15 +163,18 @@
 		  s->flags &= ~SESSION_F_RX_EVT;
 		  app->cb_fns.builtin_app_rx_callback (s);
 		}
-	      if (was_closed)
-		app_worker_close_notify (app_wrk, s);
+	      if (old_state >= SESSION_STATE_TRANSPORT_CLOSING)
+		{
+		  session_set_state (s, old_state);
+		  app_worker_close_notify (app_wrk, s);
+		}
 	    }
 	  break;
 	case SESSION_CTRL_EVT_CONNECTED:
 	  if (!(evt->as_u64[1] & 0xffffffff))
 	    {
 	      s = session_get (evt->session_index, thread_index);
-	      was_closed = s->session_state >= SESSION_STATE_TRANSPORT_CLOSING;
+	      old_state = s->session_state;
 	    }
 	  else
 	    s = 0;
@@ -185,13 +189,16 @@
 	      s->app_wrk_index = SESSION_INVALID_INDEX;
 	      break;
 	    }
-	  if (was_closed)
-	    app_worker_close_notify (app_wrk, s);
 	  if (s->flags & SESSION_F_RX_EVT)
 	    {
 	      s->flags &= ~SESSION_F_RX_EVT;
 	      app->cb_fns.builtin_app_rx_callback (s);
 	    }
+	  if (old_state >= SESSION_STATE_TRANSPORT_CLOSING)
+	    {
+	      session_set_state (s, old_state);
+	      app_worker_close_notify (app_wrk, s);
+	    }
 	  break;
 	case SESSION_CTRL_EVT_DISCONNECTED:
 	  s = session_get (evt->session_index, thread_index);