mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
res_pjsip: Deny requests when threadpool queue is backed up.
We have observed situations where the SIP threadpool may become deadlocked. However, because incoming traffic is still arriving, the SIP threadpool's queue can continue to grow, eventually running the system out of memory. This change makes it so that incoming traffic gets rejected with a 503 response if the queue is backed up too much. Change-Id: I4e736d48a2ba79fd1f8056c0dcd330e38e6a3816
This commit is contained in:
@@ -246,6 +246,8 @@ static pjsip_module endpoint_mod = {
|
||||
.on_rx_request = endpoint_lookup,
|
||||
};
|
||||
|
||||
#define SIP_MAX_QUEUE 500L
|
||||
|
||||
static pj_bool_t distributor(pjsip_rx_data *rdata)
|
||||
{
|
||||
pjsip_dialog *dlg = find_dialog(rdata);
|
||||
@@ -280,7 +282,17 @@ static pj_bool_t distributor(pjsip_rx_data *rdata)
|
||||
clone->endpt_info.mod_data[endpoint_mod.id] = ao2_bump(dist->endpoint);
|
||||
}
|
||||
|
||||
ast_sip_push_task(serializer, distribute, clone);
|
||||
if (ast_sip_threadpool_queue_size() > SIP_MAX_QUEUE) {
|
||||
/* When the threadpool is backed up this much, there is a good chance that we have encountered
|
||||
* some sort of terrible condition and don't need to be adding more work to the threadpool.
|
||||
* It's in our best interest to send back a 503 response and be done with it.
|
||||
*/
|
||||
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 503, NULL, NULL, NULL);
|
||||
ao2_cleanup(clone->endpt_info.mod_data[endpoint_mod.id]);
|
||||
pjsip_rx_data_free_cloned(clone);
|
||||
} else {
|
||||
ast_sip_push_task(serializer, distribute, clone);
|
||||
}
|
||||
|
||||
end:
|
||||
if (dlg) {
|
||||
|
Reference in New Issue
Block a user