http: timer pool assert crash fix

Two iterations over expiret timers:
1) ivalidate timer handle and mark the connection as having a pending
   timer
2) send RPCs to workers

Type: fix

Change-Id: Iadc031c4e6d6f7bbd851d0421e6e0ea2d2b5e70f
Signed-off-by: Matus Fabian <matfabia@cisco.com>
This commit is contained in:
Matus Fabian
2024-10-04 14:35:26 +02:00
committed by Florin Coras
parent b6ac2d7a7a
commit 5c8ddd54c1
4 changed files with 121 additions and 55 deletions

File diff suppressed because it is too large Load Diff

View File

@ -388,6 +388,7 @@ typedef struct http_tc_
http_conn_state_t state;
u32 timer_handle;
u8 pending_timer;
u8 *app_name;
u8 *host;
u8 is_server;

View File

@ -29,7 +29,15 @@ http_timer_process_expired_cb (u32 *expired_timers)
{
/* Get session handle. The first bit is the timer id */
hs_handle = expired_timers[i] & 0x7FFFFFFF;
session_send_rpc_evt_to_thread (hs_handle >> 24, twc->cb_fn,
twc->invalidate_cb (hs_handle);
}
for (i = 0; i < vec_len (expired_timers); i++)
{
/* Get session handle. The first bit is the timer id */
hs_handle = expired_timers[i] & 0x7FFFFFFF;
HTTP_DBG (1, "rpc to hc [%u]%x", hs_handle >> 24,
hs_handle & 0x00FFFFFF);
session_send_rpc_evt_to_thread (hs_handle >> 24, twc->rpc_cb,
uword_to_pointer (hs_handle, void *));
}
}
@ -66,7 +74,8 @@ VLIB_REGISTER_NODE (http_timer_process_node) = {
};
void
http_timers_init (vlib_main_t *vm, http_conn_timeout_fn *cb_fn)
http_timers_init (vlib_main_t *vm, http_conn_timeout_fn *rpc_cb,
http_conn_invalidate_timer_fn *invalidate_cb)
{
http_tw_ctx_t *twc = &http_tw_ctx;
vlib_node_t *n;
@ -76,7 +85,8 @@ http_timers_init (vlib_main_t *vm, http_conn_timeout_fn *cb_fn)
tw_timer_wheel_init_2t_1w_2048sl (&twc->tw, http_timer_process_expired_cb,
1.0 /* timer interval */, ~0);
clib_spinlock_init (&twc->tw_lock);
twc->cb_fn = cb_fn;
twc->rpc_cb = rpc_cb;
twc->invalidate_cb = invalidate_cb;
vlib_node_set_state (vm, http_timer_process_node.index,
VLIB_NODE_STATE_POLLING);

View File

@ -19,20 +19,24 @@
#include <http/http.h>
#include <vppinfra/tw_timer_2t_1w_2048sl.h>
#define HTTP_CONN_TIMEOUT 60
#define HTTP_CONN_TIMEOUT 60
#define HTTP_TIMER_HANDLE_INVALID ((u32) ~0)
typedef void (http_conn_timeout_fn) (void *);
typedef void (http_conn_invalidate_timer_fn) (u32 hs_handle);
typedef struct http_tw_ctx_
{
tw_timer_wheel_2t_1w_2048sl_t tw;
clib_spinlock_t tw_lock;
http_conn_timeout_fn *cb_fn;
http_conn_timeout_fn *rpc_cb;
http_conn_invalidate_timer_fn *invalidate_cb;
} http_tw_ctx_t;
extern http_tw_ctx_t http_tw_ctx;
void http_timers_init (vlib_main_t *vm, http_conn_timeout_fn *cb_fn);
void http_timers_init (vlib_main_t *vm, http_conn_timeout_fn *rpc_cb,
http_conn_invalidate_timer_fn *invalidate_cb);
static inline void
http_conn_timer_start (http_conn_t *hc)
@ -41,6 +45,7 @@ http_conn_timer_start (http_conn_t *hc)
u32 hs_handle;
u64 timeout;
ASSERT (hc->timer_handle == HTTP_TIMER_HANDLE_INVALID);
timeout = HTTP_CONN_TIMEOUT;
hs_handle = hc->c_thread_index << 24 | hc->c_c_index;
@ -55,12 +60,13 @@ http_conn_timer_stop (http_conn_t *hc)
{
http_tw_ctx_t *twc = &http_tw_ctx;
if (hc->timer_handle == ~0)
hc->pending_timer = 0;
if (hc->timer_handle == HTTP_TIMER_HANDLE_INVALID)
return;
clib_spinlock_lock (&twc->tw_lock);
tw_timer_stop_2t_1w_2048sl (&twc->tw, hc->timer_handle);
hc->timer_handle = ~0;
hc->timer_handle = HTTP_TIMER_HANDLE_INVALID;
clib_spinlock_unlock (&twc->tw_lock);
}
@ -69,14 +75,19 @@ http_conn_timer_update (http_conn_t *hc)
{
http_tw_ctx_t *twc = &http_tw_ctx;
u64 timeout;
if (hc->timer_handle == ~0)
return;
u32 hs_handle;
timeout = HTTP_CONN_TIMEOUT;
clib_spinlock_lock (&twc->tw_lock);
tw_timer_update_2t_1w_2048sl (&twc->tw, hc->timer_handle, timeout);
if (hc->timer_handle != HTTP_TIMER_HANDLE_INVALID)
tw_timer_update_2t_1w_2048sl (&twc->tw, hc->timer_handle, timeout);
else
{
hs_handle = hc->c_thread_index << 24 | hc->c_c_index;
hc->timer_handle =
tw_timer_start_2t_1w_2048sl (&twc->tw, hs_handle, 0, timeout);
}
clib_spinlock_unlock (&twc->tw_lock);
}