- if (session->session_state == VCL_STATE_VPP_CLOSING)
- vcl_session_cleanup (wrk, session, vcl_session_handle (session),
- 1 /* do_disconnect */ );
+ if (session->session_state == VCL_STATE_VPP_CLOSING
+ || session->session_state == VCL_STATE_DISCONNECT)
+ {
+ vcl_session_cleanup (wrk, session, vcl_session_handle (session),
+ 1 /* do_disconnect */ );
+ /* Move to undetermined state to ensure that the session is not
+ * removed before both vpp and the app cleanup.
+ * - If the app closes first, the session is moved to CLOSED state
+ * and the session cleanup notification from vpp removes the
+ * session.
+ * - If vpp cleans up the session first, the session is moved to
+ * DETACHED state lower and subsequently the close from the app
+ * frees the session
+ */
+ session->session_state = VCL_STATE_UPDATED;
+ }