Skip to content

Commit

Permalink
TMP trace every srv_take/srv_drop calls
Browse files Browse the repository at this point in the history
  • Loading branch information
a-denoyelle committed Oct 23, 2024
1 parent bf38568 commit 7971350
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 4 deletions.
10 changes: 9 additions & 1 deletion addons/promex/service-prometheus.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

#include <promex/promex.h>

#include <haproxy/trace.h>
extern struct trace_source trace_check;
#define TRACE_SOURCE &trace_check

/* Prometheus exporter applet states (appctx->st0) */
enum {
PROMEX_ST_INIT = 0, /* initialized */
Expand Down Expand Up @@ -1515,9 +1519,12 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
}

/* Decrement server refcount if it was saved through ctx.p[1]. */
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", ctx->p[1]);
srv_drop(ctx->p[1]);
if (sv)
if (sv) {
if (fdtab) TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_take %p", sv);
srv_take(sv);
}

/* Save pointers (0=current proxy, 1=current server, 2=current stats module) of the current context */
ctx->p[0] = px;
Expand Down Expand Up @@ -2064,6 +2071,7 @@ static void promex_appctx_release(struct appctx *appctx)

if (appctx->st1 == PROMEX_DUMPER_SRV) {
struct server *srv = objt_server(ctx->p[1]);
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", srv);
srv_drop(srv);
}

Expand Down
8 changes: 7 additions & 1 deletion src/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -1479,8 +1479,10 @@ struct task *process_chk_conn(struct task *t, void *context, unsigned int state)
*/
if (unlikely(check->state & CHK_ST_PURGE)) {
free_check(check);
if (check->server)
if (check->server) {
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", check->server);
srv_drop(check->server);
}

t = NULL;
}
Expand Down Expand Up @@ -1887,6 +1889,7 @@ int init_srv_check(struct server *srv)
goto out;
}
srv->check.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_SLEEPING;
if (fdtab) TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_take %p", srv);
srv_take(srv);

/* Only increment maxsock for servers from the configuration. Dynamic
Expand Down Expand Up @@ -1950,6 +1953,7 @@ int init_srv_agent_check(struct server *srv)
srv->agent.inter = srv->check.inter;

srv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_SLEEPING | CHK_ST_AGENT;
if (fdtab) TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_take %p", srv);
srv_take(srv);

/* Only increment maxsock for servers from the configuration. Dynamic
Expand All @@ -1968,6 +1972,7 @@ static void deinit_srv_check(struct server *srv)
if (srv->check.state & CHK_ST_CONFIGURED) {
free_check(&srv->check);
/* it is safe to drop now since the main server reference is still held by the proxy */
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", srv);
srv_drop(srv);
}
srv->check.state &= ~CHK_ST_CONFIGURED & ~CHK_ST_ENABLED;
Expand All @@ -1980,6 +1985,7 @@ static void deinit_srv_agent_check(struct server *srv)
if (srv->agent.state & CHK_ST_CONFIGURED) {
free_check(&srv->agent);
/* it is safe to drop now since the main server reference is still held by the proxy */
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", srv);
srv_drop(srv);
}

Expand Down
6 changes: 6 additions & 0 deletions src/hlua.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
#include <haproxy/check.h>
#include <haproxy/mailers.h>

#include <haproxy/trace.h>
extern struct trace_source trace_check;
#define TRACE_SOURCE &trace_check

/* Global LUA flags */

enum hlua_log_opt {
Expand Down Expand Up @@ -14368,9 +14372,11 @@ static void hlua_deinit()
lua_close(hlua_states[thr]);
}

TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", socket_tcp);
srv_drop(socket_tcp);

#ifdef USE_OPENSSL
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", socket_ssl);
srv_drop(socket_ssl);
#endif

Expand Down
6 changes: 6 additions & 0 deletions src/hlua_fcn.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#include <haproxy/tools.h>
#include <haproxy/mailers.h>

#include <haproxy/trace.h>
extern struct trace_source trace_check;
#define TRACE_SOURCE &trace_check

/* Contains the class reference of the concat object. */
static int class_concat_ref;
static int class_queue_ref;
Expand Down Expand Up @@ -1175,6 +1179,7 @@ int hlua_server_gc(lua_State *L)
{
struct server *srv = hlua_checkudata(L, 1, class_server_ref);

TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", srv);
srv_drop(srv); /* srv_drop allows NULL srv */
return 0;
}
Expand Down Expand Up @@ -1810,6 +1815,7 @@ int hlua_fcn_new_server(lua_State *L, struct server *srv)
lua_rawseti(L, -2, 0);

/* userdata is affected: increment server refcount */
if (fdtab) TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_take %p", srv);
srv_take(srv);

/* set public methods */
Expand Down
7 changes: 7 additions & 0 deletions src/http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@

#include <string.h>

#include <haproxy/trace.h>
extern struct trace_source trace_check;
#define TRACE_SOURCE &trace_check

static struct proxy *httpclient_proxy;

#ifdef USE_OPENSSL
Expand Down Expand Up @@ -1295,6 +1299,7 @@ struct proxy *httpclient_create_proxy(const char *id)
goto err;
} else {
ha_free(&srv_ssl->ssl_ctx.ca_file);
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", srv_ssl);
srv_drop(srv_ssl);
srv_ssl = NULL;
}
Expand Down Expand Up @@ -1329,8 +1334,10 @@ struct proxy *httpclient_create_proxy(const char *id)
if (err_code & ERR_CODE) {
ha_alert("httpclient: cannot initialize: %s\n", errmsg);
free(errmsg);
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", srv_raw);
srv_drop(srv_raw);
#ifdef USE_OPENSSL
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", srv_ssl);
srv_drop(srv_ssl);
#endif
free_proxy(px);
Expand Down
9 changes: 8 additions & 1 deletion src/mworker.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
#include <haproxy/systemd.h>
#endif

#include <haproxy/trace.h>
extern struct trace_source trace_check;
#define TRACE_SOURCE &trace_check

static int exitcode = -1;
int max_reloads = INT_MAX; /* max number of reloads a worker can have until they are killed */
struct mworker_proc *proc_self = NULL; /* process structure of current process */
Expand Down Expand Up @@ -372,8 +376,10 @@ void mworker_catch_sigchld(struct sig_handler *sh)
}

/* Drop server */
if (child->srv)
if (child->srv) {
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", child->srv);
srv_drop(child->srv);
}

/* Delete fd from poller fdtab, which will close it */
fd_delete(child->ipc_fd[0]);
Expand Down Expand Up @@ -578,6 +584,7 @@ void mworker_cleanup_proc()
close(child->ipc_fd[1]);
if (child->srv) {
/* only exists if we created a master CLI listener */
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", child->srv);
srv_drop(child->srv);
}
LIST_DELETE(&child->list);
Expand Down
4 changes: 4 additions & 0 deletions src/proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
#include <haproxy/time.h>
#include <haproxy/tools.h>

#include <haproxy/trace.h>
extern struct trace_source trace_check;
#define TRACE_SOURCE &trace_check

int listeners; /* # of proxy listeners, set by cfgparse */
struct proxy *proxies_list = NULL; /* list of all existing proxies */
Expand Down Expand Up @@ -353,6 +356,7 @@ void free_proxy(struct proxy *p)
while (s) {
list_for_each_entry(srvdf, &server_deinit_list, list)
srvdf->fct(s);
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", s);
s = srv_drop(s);
}/* end while(s) */

Expand Down
12 changes: 11 additions & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
#include <haproxy/xxhash.h>
#include <haproxy/event_hdl.h>

#include <haproxy/trace.h>
extern struct trace_source trace_check;
#define TRACE_SOURCE &trace_check

static void srv_update_status(struct server *s, int type, int cause);
static int srv_apply_lastaddr(struct server *srv, int *err_code);
Expand Down Expand Up @@ -2957,6 +2960,7 @@ struct server *new_server(struct proxy *proxy)
if (!srv)
return NULL;

if (fdtab) TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_take %p", srv);
srv_take(srv);

srv->obj_type = OBJ_TYPE_SERVER;
Expand Down Expand Up @@ -3069,6 +3073,7 @@ struct server *srv_drop(struct server *srv)
if (HA_ATOMIC_SUB_FETCH(&srv->refcount, 1))
goto end;

TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop::done %p", srv);
/* This BUG_ON() is invalid for now as server released on deinit will
* trigger it as they are not properly removed from their tree.
*/
Expand Down Expand Up @@ -5982,10 +5987,12 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct

if (srv->check.state & CHK_ST_CONFIGURED) {
free_check(&srv->check);
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", srv);
srv_drop(srv);
}
if (srv->agent.state & CHK_ST_CONFIGURED) {
free_check(&srv->agent);
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", srv);
srv_drop(srv);
}

Expand All @@ -5998,8 +6005,10 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
if (!usermsgs_empty())
cli_umsgerr(appctx);

if (srv)
if (srv) {
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", srv);
srv_drop(srv);
}

return 1;
}
Expand Down Expand Up @@ -6250,6 +6259,7 @@ static int cli_parse_delete_server(char **args, char *payload, struct appctx *ap
thread_release();

ha_notice("Server deleted.\n");
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", srv);
srv_drop(srv);

cli_msg(appctx, LOG_INFO, "Server deleted.\n");
Expand Down
5 changes: 5 additions & 0 deletions src/sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#include <haproxy/time.h>
#include <haproxy/tools.h>

#include <haproxy/trace.h>
extern struct trace_source trace_check;
#define TRACE_SOURCE &trace_check

struct list sink_list = LIST_HEAD_INIT(sink_list);

/* sink proxies list */
Expand Down Expand Up @@ -1258,6 +1262,7 @@ struct sink *sink_new_from_logger(struct logger *logger)

return sink;
error:
TRACE_PRINTF(TRACE_LEVEL_ERROR, 1, 0, 0, 0, 0, "srv_drop %p", srv);
srv_drop(srv);

error_final:
Expand Down

0 comments on commit 7971350

Please sign in to comment.