67ea12
diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c
67ea12
index 12214e1..3b7f892 100644
67ea12
--- a/src/http/v2/ngx_http_v2.c
67ea12
+++ b/src/http/v2/ngx_http_v2.c
67ea12
@@ -4335,6 +4335,8 @@ ngx_http_v2_close_stream(ngx_http_v2_stream_t *stream, ngx_int_t rc)
67ea12
      */
67ea12
     pool = stream->pool;
67ea12
 
67ea12
+    h2c->frames -= stream->frames;
67ea12
+
67ea12
     ngx_http_free_request(stream->request, rc);
67ea12
 
67ea12
     if (pool != h2c->state.pool) {
67ea12
diff --git a/src/http/v2/ngx_http_v2.h b/src/http/v2/ngx_http_v2.h
67ea12
index bec2216..715b7d3 100644
67ea12
--- a/src/http/v2/ngx_http_v2.h
67ea12
+++ b/src/http/v2/ngx_http_v2.h
67ea12
@@ -192,6 +192,8 @@ struct ngx_http_v2_stream_s {
67ea12
 
67ea12
     ngx_buf_t                       *preread;
67ea12
 
67ea12
+    ngx_uint_t                       frames;
67ea12
+
67ea12
     ngx_http_v2_out_frame_t         *free_frames;
67ea12
     ngx_chain_t                     *free_frame_headers;
67ea12
     ngx_chain_t                     *free_bufs;
67ea12
diff --git a/src/http/v2/ngx_http_v2_filter_module.c b/src/http/v2/ngx_http_v2_filter_module.c
67ea12
index 029e8ec..c7ee553 100644
67ea12
--- a/src/http/v2/ngx_http_v2_filter_module.c
67ea12
+++ b/src/http/v2/ngx_http_v2_filter_module.c
67ea12
@@ -1661,22 +1661,34 @@ static ngx_http_v2_out_frame_t *
67ea12
 ngx_http_v2_filter_get_data_frame(ngx_http_v2_stream_t *stream,
67ea12
     size_t len, ngx_chain_t *first, ngx_chain_t *last)
67ea12
 {
67ea12
-    u_char                    flags;
67ea12
-    ngx_buf_t                *buf;
67ea12
-    ngx_chain_t              *cl;
67ea12
-    ngx_http_v2_out_frame_t  *frame;
67ea12
+    u_char                     flags;
67ea12
+    ngx_buf_t                 *buf;
67ea12
+    ngx_chain_t               *cl;
67ea12
+    ngx_http_v2_out_frame_t   *frame;
67ea12
+    ngx_http_v2_connection_t  *h2c;
67ea12
 
67ea12
     frame = stream->free_frames;
67ea12
+    h2c = stream->connection;
67ea12
 
67ea12
     if (frame) {
67ea12
         stream->free_frames = frame->next;
67ea12
 
67ea12
-    } else {
67ea12
+    } else if (h2c->frames < 10000) {
67ea12
         frame = ngx_palloc(stream->request->pool,
67ea12
                            sizeof(ngx_http_v2_out_frame_t));
67ea12
         if (frame == NULL) {
67ea12
             return NULL;
67ea12
         }
67ea12
+
67ea12
+        stream->frames++;
67ea12
+        h2c->frames++;
67ea12
+
67ea12
+    } else {
67ea12
+        ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
67ea12
+                      "http2 flood detected");
67ea12
+
67ea12
+        h2c->connection->error = 1;
67ea12
+        return NULL;
67ea12
     }
67ea12
 
67ea12
     flags = last->buf->last_buf ? NGX_HTTP_V2_END_STREAM_FLAG : 0;