Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QPACK: Don't update known received count when stream is cancelled. #269

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void sectionAcknowledgment(long streamId) throws QpackException {
throw INVALID_SECTION_ACKNOWLEDGMENT;
}

dynamicTableIndices.forEach(dynamicTable::acknowledgeInsertCount);
dynamicTableIndices.forEach(dynamicTable::acknowledgeInsertCountOnAck);
}

/**
Expand All @@ -179,7 +179,7 @@ void streamCancellation(long streamId) throws QpackException {
if (dynamicTableIndices == null) {
break;
}
dynamicTableIndices.forEach(dynamicTable::acknowledgeInsertCount);
dynamicTableIndices.forEach(dynamicTable::acknowledgeInsertCountOnCancellation);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,31 @@ int add(CharSequence name, CharSequence value, long headerSize) {
* @param entryIndex For the entry corresponding to the {@link #insertCount()}.
* @throws QpackException If the count is invalid.
*/
void acknowledgeInsertCount(int entryIndex) throws QpackException {
void acknowledgeInsertCountOnAck(int entryIndex) throws QpackException {
acknowledgeInsertCount(entryIndex, true);
}

/**
* Callback when a header block which had a {@link #insertCount()}} greater than {@code 0} is still not processed
* and the stream is <a href="https://www.rfc-editor.org/rfc/rfc9204.html#name-stream-cancellation">cancelled</a>
* by the decoder.
*
* @param entryIndex For the entry corresponding to the {@link #insertCount()}.
* @throws QpackException If the count is invalid.
*/
void acknowledgeInsertCountOnCancellation(int entryIndex) throws QpackException {
acknowledgeInsertCount(entryIndex, false);
}

private void acknowledgeInsertCount(int entryIndex, boolean updateKnownReceived) throws QpackException {
if (entryIndex < 0) {
throw INVALID_REQUIRED_INSERT_COUNT_INCREMENT;
}
for (HeaderEntry e = head.next; e != null; e = e.next) {
if (e.index == entryIndex) {
assert e.refCount > 0;
e.refCount--;
if (e.index > knownReceived.index) {
if (updateKnownReceived && e.index > knownReceived.index) {
// https://www.rfc-editor.org/rfc/rfc9204.html#name-known-received-count
// If the Required Insert Count of the acknowledged field section is greater than the current Known
// Received Count, Known Received Count is updated to that Required Insert Count value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void sectionAck() throws Exception {

final int idx = addAndValidateHeader(table, fooBarHeader);
table.addReferenceToEntry(fooBarHeader.name, fooBarHeader.value, idx);
table.acknowledgeInsertCount(idx);
table.acknowledgeInsertCountOnAck(idx);

assertThat("Unexpected known received count.", table.encodedKnownReceivedCount(), is(2));
}
Expand All @@ -176,10 +176,10 @@ public void sectionAckOutOfOrder() throws Exception {
final int idx2 = addAndValidateHeader(table, fooBarHeader);
table.addReferenceToEntry(fooBarHeader.name, fooBarHeader.value, idx2);

table.acknowledgeInsertCount(idx2);
table.acknowledgeInsertCountOnAck(idx2);
assertThat("Unexpected known received count.", table.encodedKnownReceivedCount(), is(3));

table.acknowledgeInsertCount(idx1);
table.acknowledgeInsertCountOnAck(idx1);
assertThat("Unexpected known received count.", table.encodedKnownReceivedCount(), is(3)); // already acked
}

Expand All @@ -192,12 +192,12 @@ public void multipleReferences() throws Exception {
table.addReferenceToEntry(fooBar3Header.name, fooBar3Header.value, idx1);
table.addReferenceToEntry(fooBar3Header.name, fooBar3Header.value, idx1);

table.acknowledgeInsertCount(idx1);
table.acknowledgeInsertCountOnAck(idx1);

// first entry still active
assertThat("Header added", addHeader(table, fooBar2Header), lessThan(0));

table.acknowledgeInsertCount(idx1);
table.acknowledgeInsertCountOnAck(idx1);
verifyTableEmpty(table);
addAndValidateHeader(table, fooBarHeader);
}
Expand Down Expand Up @@ -229,7 +229,7 @@ private int addAndValidateHeader(QpackEncoderDynamicTable table, QpackHeaderFiel
private int addValidateAndAckHeader(QpackEncoderDynamicTable table, QpackHeaderField header) throws Exception {
final int addedIdx = addAndValidateHeader(table, header);
table.addReferenceToEntry(header.name, header.value, addedIdx);
table.acknowledgeInsertCount(addedIdx);
table.acknowledgeInsertCountOnAck(addedIdx);
return addedIdx;
}

Expand Down