You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2017/11/30 16:23:34 UTC
[trafficserver] branch master updated: Limit the amount of memory
that an HTTP/2 stream will allocate
This is an automated email from the ASF dual-hosted git repository.
bcall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new ccea2ae Limit the amount of memory that an HTTP/2 stream will allocate
ccea2ae is described below
commit ccea2aea865647fcee5a3b693abbf97202bb64ab
Author: Bryan Call <bc...@apache.org>
AuthorDate: Mon Sep 18 12:21:49 2017 -0700
Limit the amount of memory that an HTTP/2 stream will allocate
---
proxy/http2/HTTP2.h | 1 +
proxy/http2/Http2ClientSession.h | 6 ++++++
proxy/http2/Http2Stream.cc | 17 +++++++++++++++++
proxy/http2/Http2Stream.h | 3 ++-
4 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/proxy/http2/HTTP2.h b/proxy/http2/HTTP2.h
index d205566..c6e8989 100644
--- a/proxy/http2/HTTP2.h
+++ b/proxy/http2/HTTP2.h
@@ -62,6 +62,7 @@ const uint32_t HTTP2_INITIAL_WINDOW_SIZE = 65535;
const uint32_t HTTP2_MAX_FRAME_SIZE = 16384;
const uint32_t HTTP2_HEADER_TABLE_SIZE = 4096;
const uint32_t HTTP2_MAX_HEADER_LIST_SIZE = UINT_MAX;
+const uint32_t HTTP2_MAX_BUFFER_USAGE = 524288;
// [RFC 7540] 5.3.5 Default Priorities
// The RFC says weight value is 1 to 256, but the value in TS is between 0 to 255
diff --git a/proxy/http2/Http2ClientSession.h b/proxy/http2/Http2ClientSession.h
index 42f0afb..9b46afb 100644
--- a/proxy/http2/Http2ClientSession.h
+++ b/proxy/http2/Http2ClientSession.h
@@ -312,6 +312,12 @@ public:
}
}
+ int64_t
+ write_buffer_size()
+ {
+ return write_buffer->max_read_avail();
+ }
+
// noncopyable
Http2ClientSession(Http2ClientSession &) = delete;
Http2ClientSession &operator=(const Http2ClientSession &) = delete;
diff --git a/proxy/http2/Http2Stream.cc b/proxy/http2/Http2Stream.cc
index e42a3f1..e69ecc5 100644
--- a/proxy/http2/Http2Stream.cc
+++ b/proxy/http2/Http2Stream.cc
@@ -61,6 +61,8 @@ Http2Stream::main_event_handler(int event, void *edata)
read_event = nullptr;
} else if (e == write_event) {
write_event = nullptr;
+ } else if (e == buffer_full_write_event) {
+ buffer_full_write_event = nullptr;
}
switch (event) {
@@ -548,6 +550,16 @@ Http2Stream::update_write_request(IOBufferReader *buf_reader, int64_t write_len,
if (bytes_avail > num_to_write) {
bytes_avail = num_to_write;
}
+
+ if (static_cast<Http2ClientSession *>(parent)->write_buffer_size() > HTTP2_MAX_BUFFER_USAGE ||
+ response_buffer.max_read_avail() > HTTP2_MAX_BUFFER_USAGE ||
+ (chunked_handler.dechunked_buffer && chunked_handler.dechunked_buffer->max_read_avail() > HTTP2_MAX_BUFFER_USAGE)) {
+ if (buffer_full_write_event == nullptr) {
+ buffer_full_write_event = get_thread()->schedule_imm(this, VC_EVENT_WRITE_READY);
+ }
+ return true;
+ }
+
while (total_added < bytes_avail) {
int64_t bytes_added = response_buffer.write(buf_reader, bytes_avail);
buf_reader->consume(bytes_added);
@@ -852,6 +864,11 @@ Http2Stream::clear_io_events()
write_event->cancel();
}
write_event = nullptr;
+
+ if (buffer_full_write_event) {
+ buffer_full_write_event->cancel();
+ buffer_full_write_event = nullptr;
+ }
}
void
diff --git a/proxy/http2/Http2Stream.h b/proxy/http2/Http2Stream.h
index 7c1840b..6405e87 100644
--- a/proxy/http2/Http2Stream.h
+++ b/proxy/http2/Http2Stream.h
@@ -275,7 +275,8 @@ private:
uint64_t bytes_sent = 0;
ChunkedHandler chunked_handler;
- Event *cross_thread_event = nullptr;
+ Event *cross_thread_event = nullptr;
+ Event *buffer_full_write_event = nullptr;
// Support stream-specific timeouts
ink_hrtime active_timeout = 0;
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].