Skip to content

Commit

Permalink
BUG/MEDIUM: server: fix crash on server deletion due to servers_list
Browse files Browse the repository at this point in the history
  • Loading branch information
a-denoyelle committed Oct 23, 2024
1 parent cdb9f33 commit 9f0cc4c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/haproxy/server-t.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ struct server {
signed char use_ssl; /* ssl enabled (1: on, 0: disabled, -1 forced off) */
unsigned int flags; /* server flags (SRV_F_*) */
unsigned int pp_opts; /* proxy protocol options (SRV_PP_*) */
struct list global_list; /* attach point in the global servers_list */
struct mt_list global_list; /* attach point in the global servers_list */
struct server *next;
struct mt_list prev_deleted; /* deleted servers with 'next' ptr pointing to us */
int cklen; /* the len of the cookie, to speed up checks */
Expand Down
2 changes: 1 addition & 1 deletion include/haproxy/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
__decl_thread(extern HA_SPINLOCK_T idle_conn_srv_lock);
extern struct idle_conns idle_conns[MAX_THREADS];
extern struct task *idle_conn_task;
extern struct list servers_list;
extern struct mt_list servers_list;
extern struct dict server_key_dict;

int srv_downtime(const struct server *s);
Expand Down
3 changes: 2 additions & 1 deletion src/cfgparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2810,6 +2810,7 @@ int check_config_validity()
struct proxy *init_proxies_list = NULL;
struct stktable *t;
struct server *newsrv = NULL;
struct mt_list back;
int err_code = 0;
unsigned int next_pxid = 1;
struct bind_conf *bind_conf;
Expand Down Expand Up @@ -4250,7 +4251,7 @@ int check_config_validity()

/* we must finish to initialize certain things on the servers */

list_for_each_entry(newsrv, &servers_list, global_list) {
MT_LIST_FOR_EACH_ENTRY_LOCKED(newsrv, &servers_list, global_list, back) {
/* initialize idle conns lists */
if (srv_init_per_thr(newsrv) == -1) {
ha_alert("parsing [%s:%d] : failed to allocate per-thread lists for server '%s'.\n",
Expand Down
8 changes: 4 additions & 4 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct srv_kw_list srv_keywords = {
__decl_thread(HA_SPINLOCK_T idle_conn_srv_lock);
struct eb_root idle_conn_srv = EB_ROOT;
struct task *idle_conn_task __read_mostly = NULL;
struct list servers_list = LIST_HEAD_INIT(servers_list);
struct mt_list servers_list = MT_LIST_HEAD_INIT(servers_list);
static struct task *server_atomic_sync_task = NULL;
static event_hdl_async_equeue server_atomic_sync_queue;

Expand Down Expand Up @@ -2966,7 +2966,7 @@ struct server *new_server(struct proxy *proxy)
srv->obj_type = OBJ_TYPE_SERVER;
srv->proxy = proxy;
queue_init(&srv->queue, proxy, srv);
LIST_APPEND(&servers_list, &srv->global_list);
MT_LIST_APPEND(&servers_list, &srv->global_list);
LIST_INIT(&srv->srv_rec_item);
LIST_INIT(&srv->ip_rec_item);
LIST_INIT(&srv->pp_tlvs);
Expand Down Expand Up @@ -3099,7 +3099,7 @@ struct server *srv_drop(struct server *srv)

HA_SPIN_DESTROY(&srv->lock);

LIST_DELETE(&srv->global_list);
MT_LIST_DELETE(&srv->global_list);
event_hdl_sub_list_destroy(&srv->e_subs);

EXTRA_COUNTERS_FREE(srv->extra_counters);
Expand Down Expand Up @@ -3278,7 +3278,7 @@ static int _srv_parse_tmpl_init(struct server *srv, struct proxy *px)
release_sample_expr(newsrv->ssl_ctx.sni);
free_check(&newsrv->agent);
free_check(&newsrv->check);
LIST_DELETE(&newsrv->global_list);
MT_LIST_DELETE(&newsrv->global_list);
}
free(newsrv);
return i - srv->tmpl_info.nb_low;
Expand Down

0 comments on commit 9f0cc4c

Please sign in to comment.