From 3d07a16f1466ebe3cd91de78fb844a046af0a8b5 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 25 Apr 2019 19:15:20 +0200 Subject: [PATCH] MEDIUM: stream/debug: force a crash if a stream spins over itself forever If a stream is caught spinning over itself at more than 100000 loops per second and for more than one second, the process will be aborted and the offender reported on the console and logs. Typical figures usually are just a few tens to hundreds per second over a very short time so there is a huge margin here. Using even higher values could also work but there is the risk of not being able to catch offenders if multiple ones start to bug at the same time and share the load. This code should ideally be disabled for stable releases, though in theory nothing should ever trigger it. --- src/stream.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/stream.c b/src/stream.c index 4df5ff285..5ef450dcc 100644 --- a/src/stream.c +++ b/src/stream.c @@ -1711,6 +1711,7 @@ struct task *process_stream(struct task *t, void *context, unsigned short state) unsigned int req_ana_back; struct channel *req, *res; struct stream_interface *si_f, *si_b; + unsigned int rate; activity[tid].stream++; @@ -1725,7 +1726,10 @@ struct task *process_stream(struct task *t, void *context, unsigned short state) si_sync_recv(si_b); redo: - update_freq_ctr(&s->call_rate, 1); + rate = update_freq_ctr(&s->call_rate, 1); + if (rate >= 100000 && s->call_rate.prev_ctr) { // make sure to wait at least a full second + stream_dump_and_crash(&s->obj_type, read_freq_ctr(&s->call_rate)); + } //DPRINTF(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__, // si_f->state, si_b->state, si_b->err_type, req->flags, res->flags);