tls: fix disconnects for sessions with pending data
[vpp.git] / src / vnet / session / session_node.c
index f5aed74..9a954bb 100644 (file)
@@ -730,6 +730,8 @@ session_tx_fifo_dequeue_internal (vlib_main_t * vm,
                                  stream_session_t * s, int *n_tx_pkts)
 {
   application_t *app;
+  if (PREDICT_FALSE (s->session_state == SESSION_STATE_CLOSED))
+    return 0;
   app = application_get (s->t_app_index);
   svm_fifo_unset_event (s->server_tx_fifo);
   return app->cb_fns.builtin_app_tx_callback (s);
@@ -817,7 +819,7 @@ skip_dequeue:
     {
       stream_session_t *s;     /* $$$ prefetch 1 ahead maybe */
       session_event_t *e;
-      u8 is_full;
+      u8 want_tx_evt;
 
       e = &fifo_events[i];
       switch (e->event_type)
@@ -836,18 +838,19 @@ skip_dequeue:
              clib_warning ("It's dead, Jim!");
              continue;
            }
-         is_full = svm_fifo_is_full (s->server_tx_fifo);
 
+         want_tx_evt = svm_fifo_want_tx_evt (s->server_tx_fifo);
          /* Spray packets in per session type frames, since they go to
           * different nodes */
          rv = (smm->session_tx_fns[s->session_type]) (vm, node, e, s,
                                                       &n_tx_packets);
          if (PREDICT_TRUE (rv == SESSION_TX_OK))
            {
-             /* Notify app there's tx space if not polling */
-             if (PREDICT_FALSE (is_full
-                                && !svm_fifo_has_event (s->server_tx_fifo)))
-               session_dequeue_notify (s);
+             if (PREDICT_FALSE (want_tx_evt))
+               {
+                 svm_fifo_set_want_tx_evt (s->server_tx_fifo, 0);
+                 session_dequeue_notify (s);
+               }
            }
          else if (PREDICT_FALSE (rv == SESSION_TX_NO_BUFFERS))
            {
@@ -877,13 +880,18 @@ skip_dequeue:
          break;
        case FIFO_EVENT_BUILTIN_RX:
          s = session_event_get_session (e, thread_index);
-         if (PREDICT_FALSE (!s))
+         if (PREDICT_FALSE (!s || s->session_state >= SESSION_STATE_CLOSING))
            continue;
          svm_fifo_unset_event (s->server_rx_fifo);
          app_wrk = app_worker_get (s->app_wrk_index);
          app = application_get (app_wrk->app_index);
          app->cb_fns.builtin_app_rx_callback (s);
          break;
+       case FIFO_EVENT_BUILTIN_TX:
+         s = session_get_from_handle_if_valid (e->session_handle);
+         if (PREDICT_TRUE (s != 0))
+           session_tx_fifo_dequeue_internal (vm, node, e, s, &n_tx_packets);
+         break;
        case FIFO_EVENT_RPC:
          fp = e->rpc_args.fp;
          (*fp) (e->rpc_args.arg);