Mercurial > hg > nginx-quic
view src/os/unix/ngx_thread_cond.c @ 7386:9200b41db765 stable-1.14
HTTP/2: limit the number of idle state switches.
An attack that continuously switches HTTP/2 connection between
idle and active states can result in excessive CPU usage.
This is because when a connection switches to the idle state,
all of its memory pool caches are freed.
This change limits the maximum allowed number of idle state
switches to 10 * http2_max_requests (i.e., 10000 by default).
This limits possible CPU usage in one connection, and also
imposes a limit on the maximum lifetime of a connection.
Initially reported by Gal Goldshtein from F5 Networks.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Tue, 06 Nov 2018 16:29:49 +0300 |
parents | 022ea0d17177 |
children |
line wrap: on
line source
/* * Copyright (C) Igor Sysoev * Copyright (C) Nginx, Inc. */ #include <ngx_config.h> #include <ngx_core.h> ngx_int_t ngx_thread_cond_create(ngx_thread_cond_t *cond, ngx_log_t *log) { ngx_err_t err; err = pthread_cond_init(cond, NULL); if (err == 0) { return NGX_OK; } ngx_log_error(NGX_LOG_EMERG, log, err, "pthread_cond_init() failed"); return NGX_ERROR; } ngx_int_t ngx_thread_cond_destroy(ngx_thread_cond_t *cond, ngx_log_t *log) { ngx_err_t err; err = pthread_cond_destroy(cond); if (err == 0) { return NGX_OK; } ngx_log_error(NGX_LOG_EMERG, log, err, "pthread_cond_destroy() failed"); return NGX_ERROR; } ngx_int_t ngx_thread_cond_signal(ngx_thread_cond_t *cond, ngx_log_t *log) { ngx_err_t err; err = pthread_cond_signal(cond); if (err == 0) { return NGX_OK; } ngx_log_error(NGX_LOG_EMERG, log, err, "pthread_cond_signal() failed"); return NGX_ERROR; } ngx_int_t ngx_thread_cond_wait(ngx_thread_cond_t *cond, ngx_thread_mutex_t *mtx, ngx_log_t *log) { ngx_err_t err; err = pthread_cond_wait(cond, mtx); #if 0 ngx_time_update(); #endif if (err == 0) { return NGX_OK; } ngx_log_error(NGX_LOG_ALERT, log, err, "pthread_cond_wait() failed"); return NGX_ERROR; }