GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Respect SETTINGS_QPACK_BLOCKED_STREAMS for unacknowledged QPACK entri… · netty/netty@8ee32af

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http3/src
    • main/java/io/netty/handler/codec/http3
      • QpackEncoder.java
      • QpackEncoderDynamicTable.java
    • test/java/io/netty/handler/codec/http3
      • QpackEncoderDecoderTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http3/src/main/java/io/netty/handler/codec/http3/QpackEncoder.java‎

Copy file name to clipboardExpand all lines: codec-http3/src/main/java/io/netty/handler/codec/http3/QpackEncoder.java
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ private int encodeHeader(QpackAttributes qpackAttributes, ByteBuf out, int base,
280280
return dynamicTblIdx;
281281
}
282282
final int nameIdx = index ^ QpackStaticTable.MASK_NAME_REF;
283-
dynamicTblIdx = tryAddToDynamicTable(qpackAttributes, true, nameIdx, name, value);
283+
if (dynamicTblIdx == DYNAMIC_TABLE_ENCODE_NOT_DONE) {
284+
dynamicTblIdx = tryAddToDynamicTable(qpackAttributes, true, nameIdx, name, value);
285+
}
284286
if (dynamicTblIdx >= 0) {
285287
if (dynamicTblIdx >= base) {
286288
encodePostBaseIndexed(out, base, dynamicTblIdx);
@@ -371,6 +373,14 @@ private int tryEncodeWithDynamicTable(QpackAttributes qpackAttributes, ByteBuf o
371373
// Add to the table but do not use the entry in the header block to avoid blocking.
372374
return DYNAMIC_TABLE_ENCODE_NOT_POSSIBLE;
373375
}
376+
blockedStreams++;
377+
} else if (!dynamicTable.isKnownReceived(idx)) {
378+
// The decoder may not have received this entry yet, so referencing it may block the stream.
379+
// See https://www.rfc-editor.org/rfc/rfc9204.html#section-2.1.2
380+
if (mayNotBlockStream()) {
381+
return DYNAMIC_TABLE_ENCODE_NOT_POSSIBLE;
382+
}
383+
blockedStreams++;
374384
}
375385
if (idx >= base) {
376386
encodePostBaseIndexed(out, base, idx);
Collapse file

‎codec-http3/src/main/java/io/netty/handler/codec/http3/QpackEncoderDynamicTable.java‎

Copy file name to clipboardExpand all lines: codec-http3/src/main/java/io/netty/handler/codec/http3/QpackEncoderDynamicTable.java
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,18 @@ int addReferenceToEntry(@Nullable CharSequence name, @Nullable CharSequence valu
349349
throw new IllegalArgumentException("Index " + idx + " not found");
350350
}
351351

352+
/**
353+
* Returns {@code true} if the decoder acknowledged the entry at the passed {@code idx}, which means it can be
354+
* referenced in a field section without blocking the stream.
355+
* See <a href="https://www.rfc-editor.org/rfc/rfc9204.html#name-known-received-count">known received count</a>.
356+
*
357+
* @param idx of the entry.
358+
* @return {@code true} if the entry was acknowledged by the decoder.
359+
*/
360+
boolean isKnownReceived(int idx) {
361+
return idx <= knownReceived.index;
362+
}
363+
352364
boolean requiresDuplication(int idx, long size) {
353365
assert head != tail;
354366

Collapse file

‎codec-http3/src/test/java/io/netty/handler/codec/http3/QpackEncoderDecoderTest.java‎

Copy file name to clipboardExpand all lines: codec-http3/src/test/java/io/netty/handler/codec/http3/QpackEncoderDecoderTest.java
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import static org.hamcrest.MatcherAssert.assertThat;
3838
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3939
import static org.hamcrest.Matchers.is;
40+
import static org.hamcrest.Matchers.lessThanOrEqualTo;
4041
import static org.hamcrest.Matchers.notNullValue;
4142
import static org.junit.jupiter.api.Assertions.assertThrows;
4243
import static org.mockito.ArgumentMatchers.anyInt;
@@ -333,6 +334,58 @@ public void duplicateWithBlockedStreams() throws Exception {
333334
verifyDecodedHeader(oldEntry.name, oldEntry.value);
334335
}
335336

337+
@Test
338+
public void unacknowledgedEntryNotReferencedWithoutBlockedStreams() throws Exception {
339+
setup(128, 0);
340+
// The decoder does not acknowledge the insert (yet), e.g. the Insert Count Increment is still in flight.
341+
stateSyncStrategyAckNextInsert = false;
342+
343+
encHeaders.add("foo", "bar");
344+
encode(out, encHeaders);
345+
assertThat(encDynamicTable.insertCount(), is(1));
346+
decode(out, decHeaders);
347+
verifyDecodedHeader("foo", "bar");
348+
349+
// SETTINGS_QPACK_BLOCKED_STREAMS is 0, so the next field section must not reference the entry that is not
350+
// acknowledged yet, as the stream could become blocked.
351+
// See https://www.rfc-editor.org/rfc/rfc9204.html#section-2.1.2
352+
resetState();
353+
encHeaders.add("foo", "bar");
354+
encode(out, encHeaders);
355+
assertThat("Required Insert Count", out.getByte(0), is((byte) 0));
356+
decode(out, decHeaders);
357+
verifyDecodedHeader("foo", "bar");
358+
359+
// Once acknowledged the entry is used.
360+
encoder.insertCountIncrement(1);
361+
resetState();
362+
encHeaders.add("foo", "bar");
363+
encode(out, encHeaders);
364+
verifyRequiredInsertCount(1);
365+
assertThat("Required Insert Count", out.getByte(0), is((byte) (1 % (2 * maxEntries) + 1)));
366+
decode(out, decHeaders);
367+
verifyDecodedHeader("foo", "bar");
368+
}
369+
370+
@Test
371+
public void unacknowledgedEntryReferencesRespectMaxBlockedStreams() throws Exception {
372+
setup(128, 2);
373+
374+
int sectionsReferencingUnacknowledgedEntries = 0;
375+
for (int i = 0; i < 3; i++) {
376+
resetState();
377+
encHeaders.add("foo", "bar");
378+
encode(out, encHeaders);
379+
// Nothing was acknowledged by the decoder, so every field section with a Required Insert Count may
380+
// block.
381+
if (out.getByte(0) != 0) {
382+
sectionsReferencingUnacknowledgedEntries++;
383+
}
384+
}
385+
drainAllSuspendedEncoderInstructions();
386+
assertThat(sectionsReferencingUnacknowledgedEntries, lessThanOrEqualTo(2));
387+
}
388+
336389
private void testDynamicTableIndexed(CharSequence name, CharSequence value) throws Exception {
337390
encHeaders.add(name, value);
338391
encode(out, encHeaders);

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.