Skip to content

Commit

Permalink
Change the starting overhead count from -10 to -10*overheadCountFactor
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Jun 15, 2021
1 parent 8996960 commit caafb95
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 9 additions & 1 deletion java/org/apache/coyote/http2/Http2UpgradeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Http2UpgradeHandler extends AbstractStream implements InternalHttpUpgradeH
private Queue<StreamRunnable> queuedRunnable = null;

// Track 'overhead' frames vs 'request/response' frames
private final AtomicLong overheadCount = new AtomicLong(-10);
private final AtomicLong overheadCount;
private volatile int lastNonFinalDataPayload;
private volatile int lastWindowUpdate;

Expand All @@ -154,6 +154,14 @@ class Http2UpgradeHandler extends AbstractStream implements InternalHttpUpgradeH
this.adapter = adapter;
this.connectionId = Integer.toString(connectionIdGenerator.getAndIncrement());

// Defaults to -10 * the count factor.
// i.e. when the connection opens, 10 'overhead' frames in a row will
// cause the connection to be closed.
// Over time the count should be a slowly decreasing negative number.
// Therefore, the longer a connection is 'well-behaved', the greater
// tolerance it will have for a period of 'bad' behaviour.
overheadCount = new AtomicLong(-10 * protocol.getOverheadCountFactor());

lastNonFinalDataPayload = protocol.getOverheadDataThreshold() * 2;
lastWindowUpdate = protocol.getOverheadWindowUpdateThreshold() * 2;

Expand Down
7 changes: 7 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@
1. This means that, over time, the overhead count for a well-behaved
connection will trend downwards. (markt)
</update>
<update>
Change the initial HTTP/2 overhead count from <code>-10</code> to
<code>-10 * overheadCountFactor</code>. This means that, regardless of
the value chosen for <code>overheadCountFactor</code>, when a connection
opens 10 overhead frames in a row will be required to trigger the
overhead protection. (markt)
</update>
</changelog>
</subsection>
<subsection name="Other">
Expand Down
12 changes: 6 additions & 6 deletions webapps/docs/config/http2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@
<attribute name="overheadCountFactor" required="false">
<p>The factor to apply when counting overhead frames to determine if a
connection has too high an overhead and should be closed. The overhead
count starts at <code>-10</code>. The count is decreased by 2 for each
data frame sent or received and each headers frame received. The count is
increased by the <code>overheadCountFactor</code>for each setting
received, priority frame received and ping received. If the overhead count
exceeds zero, the connection is closed. A value of less than
<code>1</code> disables this protection. In normal usage a value of
count starts at <code>-10 * overheadCountFactor</code>. The count is
decreased by 2 for each data frame sent or received and each headers frame
received. The count is increased by the <code>overheadCountFactor</code>
for each setting received, priority frame received and ping received. If
the overhead count exceeds zero, the connection is closed. A value of less
than <code>1</code> disables this protection. In normal usage a value of
<code>3</code> or more will close the connection before any streams can
complete. If not specified, a default value of <code>1</code> will be
used.</p>
Expand Down

0 comments on commit caafb95

Please sign in to comment.