session: fix ct cleanup before full establishement 55/29655/5
authorFlorin Coras <fcoras@cisco.com>
Wed, 28 Oct 2020 23:41:26 +0000 (16:41 -0700)
committerDave Barach <openvpp@barachs.net>
Thu, 29 Oct 2020 21:31:25 +0000 (21:31 +0000)
Type: fix

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

src/plugins/unittest/session_test.c
src/vnet/session/application_local.c

index 37b4dac..c152a8a 100644 (file)
@@ -376,7 +376,18 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input)
 
   /* wait for stuff to happen */
   while (connected_session_index == ~0 && ++tries < 100)
-    vlib_process_suspend (vm, 100e-3);
+    {
+      vlib_worker_thread_barrier_release (vm);
+      vlib_process_suspend (vm, 100e-3);
+      vlib_worker_thread_barrier_sync (vm);
+    }
+  while (accepted_session_index == ~0 && ++tries < 100)
+    {
+      vlib_worker_thread_barrier_release (vm);
+      vlib_process_suspend (vm, 100e-3);
+      vlib_worker_thread_barrier_sync (vm);
+    }
+
   clib_warning ("waited %.1f seconds for connections", tries / 10.0);
   SESSION_TEST ((connected_session_index != ~0), "session should exist");
   SESSION_TEST ((connected_session_thread != ~0), "thread should exist");
@@ -422,7 +433,7 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input)
 static int
 session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
 {
-  u64 options[APP_OPTIONS_N_OPTIONS], placeholder_secret = 1234;
+  u64 options[APP_OPTIONS_N_OPTIONS], placeholder_secret = 1234, tries;
   u32 server_index, server_st_index, server_local_st_index;
   u32 placeholder_port = 1234, client_index, server_wrk_index;
   u32 placeholder_api_context = 4321, placeholder_client_api_index = ~0;
@@ -609,6 +620,19 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   connect_args.sep.ip.ip4.as_u8[0] = 127;
   error = vnet_connect (&connect_args);
   SESSION_TEST ((error == 0), "client connect should not return error code");
+
+  /* wait for accept */
+  if (vlib_num_workers ())
+    {
+      tries = 0;
+      while (!placeholder_accept && ++tries < 100)
+       {
+         vlib_worker_thread_barrier_release (vm);
+         vlib_process_suspend (vm, 100e-3);
+         vlib_worker_thread_barrier_sync (vm);
+       }
+    }
+
   SESSION_TEST ((placeholder_segment_count == 1),
                "should've received request to map new segment");
   SESSION_TEST ((placeholder_accept == 1),
index 9de987d..dc77756 100644 (file)
@@ -274,6 +274,7 @@ ct_accept_rpc_wrk_handler (void *accept_args)
   clib_memcpy (&cct->c_rmt_ip, &args->ip, sizeof (args->ip));
   cct->actual_tp = ll_ct->actual_tp;
   cct->is_client = 1;
+  cct->c_s_index = ~0;
 
   /*
    * Init server transport
@@ -465,7 +466,11 @@ ct_session_close (u32 ct_index, u32 thread_index)
   if (peer_ct)
     {
       peer_ct->peer_index = ~0;
-      session_transport_closing_notify (&peer_ct->connection);
+      /* Make sure session was allocated */
+      if (peer_ct->c_s_index != ~0)
+       session_transport_closing_notify (&peer_ct->connection);
+      else
+       ct_connection_free (peer_ct);
     }
 
   s = session_get (ct->c_s_index, ct->c_thread_index);