Skip to content

Commit

Permalink
Merge pull request #1689 from fl4via/backport-fixes_2.2.x
Browse files Browse the repository at this point in the history
[UNDERTOW-2412 / 2445 / 2449 / 2446 / 2436 / 2422 / 2444 / 2448] Backport fixes to 2.2.x
  • Loading branch information
fl4via authored Oct 16, 2024
2 parents 13801c0 + 71fd264 commit 5749332
Show file tree
Hide file tree
Showing 11 changed files with 337 additions and 110 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ jobs:
shell: bash
run: tar -czf maven-repo.tgz -C ~ .m2/repository
- name: Persist Maven Repo
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: maven-repo
path: maven-repo.tgz
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
if: failure()
with:
name: surefire-reports-build
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
hostname || true
- uses: actions/checkout@v2
- name: Download Maven Repo
uses: actions/download-artifact@v1
uses: actions/download-artifact@v4
with:
name: maven-repo
path: .
Expand All @@ -130,7 +130,7 @@ jobs:
run: mvn -v
- name: Run Tests
run: mvn -U -B -fae test -Pproxy '-DfailIfNoTests=false' -pl ${{ matrix.module }}
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
if: failure()
with:
name: surefire-reports-${{ matrix.jdk }}-${{ matrix.module }}-${{ matrix.os }}
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
hostname || true
- uses: actions/checkout@v2
- name: Download Maven Repo
uses: actions/download-artifact@v1
uses: actions/download-artifact@v4
with:
name: maven-repo
path: .
Expand All @@ -182,7 +182,7 @@ jobs:
run: mvn -v
- name: Run Tests
run: mvn -U -B -fae test ${{ matrix.proxy }} '-DfailIfNoTests=false' -pl ${{ matrix.module }} -Dtest.ipv6=true
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
if: failure()
with:
name: surefire-reports-${{ matrix.jdk }}-ipv6-${{ matrix.module }}${{ matrix.proxy }}-${{ matrix.os }}
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/io/undertow/UndertowMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -643,4 +643,10 @@ public interface UndertowMessages {

@Message(id = 207, value = "Invalid SNI hostname '%s'")
IllegalArgumentException invalidSniHostname(String hostNameValue, @Cause Throwable t);

// 208 placeholder

@Message(id = 209, value = "Protocol string was too large for the buffer. Either provide a smaller message or a bigger buffer. Protocol: %s")
IllegalStateException protocolTooLargeForBuffer(String protocolString);

}
5 changes: 5 additions & 0 deletions core/src/main/java/io/undertow/attribute/StoredResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ private String extractCharset(HeaderMap headers) {
if(contentType.startsWith("text/")) {
return StandardCharsets.ISO_8859_1.displayName();
}
// json has no charset param: https://www.iana.org/assignments/media-types/application/json
// the default is UTF-8: https://www.rfc-editor.org/rfc/rfc7158#section-8.1 & https://www.rfc-editor.org/rfc/rfc8259#section-8.1
if(contentType.equals("application/json")) {
return StandardCharsets.UTF_8.name();
}
return null;
}
return null;
Expand Down
39 changes: 36 additions & 3 deletions core/src/main/java/io/undertow/protocols/http2/Http2Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@ private StreamHolder handleRstStream(int streamId, boolean receivedRst) {
resetStreamTracker.store(streamId, holder);
if(streamId % 2 == (isClient() ? 1 : 0)) {
sendConcurrentStreamsAtomicUpdater.getAndDecrement(this);
holder.sent = true;
} else {
receiveConcurrentStreamsAtomicUpdater.getAndDecrement(this);
}
Expand All @@ -1235,13 +1236,14 @@ private StreamHolder handleRstStream(int streamId, boolean receivedRst) {
//Server side originated, no input from client other than RST
//this can happen on page refresh when push happens, but client
//still has valid cache entry
//NOTE: this is specific case when its set.
holder.resetByPeer = receivedRst;
} else {
handleRstWindow();
}
}
} else if(receivedRst){
final StreamHolder resetStream = resetStreamTracker.find(streamId);
final StreamHolder resetStream = resetStreamTracker.find(streamId, true);
if(resetStream != null && resetStream.resetByPeer) {
//This means other side reset stream at some point.
//depending on peer or network latency our frames might be late and
Expand Down Expand Up @@ -1374,6 +1376,10 @@ private static final class StreamHolder {
* This flag is set only in case of short lived server push that was reset by remote end.
*/
boolean resetByPeer = false;
/**
* flag indicate whether our side originated. This is done for caching purposes, handlng differs.
*/
boolean sent = false;
Http2StreamSourceChannel sourceChannel;
Http2StreamSinkChannel sinkChannel;

Expand All @@ -1384,6 +1390,13 @@ private static final class StreamHolder {
StreamHolder(Http2StreamSinkChannel sinkChannel) {
this.sinkChannel = sinkChannel;
}

@Override
public String toString() {
return "StreamHolder [sourceClosed=" + sourceClosed + ", sinkClosed=" + sinkClosed + ", resetByPeer=" + resetByPeer
+ ", sent=" + sent + ", sourceChannel=" + sourceChannel + ", sinkChannel=" + sinkChannel + "]";
}

}

// cache that keeps track of streams until they can be evicted @see Http2Channel#RST_STREAM_EVICATION_TIME
Expand All @@ -1399,12 +1412,27 @@ private void store(int streamId, StreamHolder streamHolder) {
streamHolders.put(streamId, streamHolder);
entries.add(new StreamCacheEntry(streamId));
}
private StreamHolder find(int streamId) {

/**
* Method will return only sent
* @param streamId
* @return
*/
private StreamHolder find(final int streamId) {
return find(streamId, false);
}

private StreamHolder find(final int streamId, final boolean all) {
for (Iterator<StreamCacheEntry> iterator = entries.iterator(); iterator.hasNext();) {
StreamCacheEntry entry = iterator.next();
if (entry.shouldEvict()) {
iterator.remove();
StreamHolder holder = streamHolders.remove(entry.streamId);
if(!holder.sent || holder.resetByPeer) {
//if its not our end of chain, its just cached, so we only cache for purpose of
// handling eager RST
continue;
}
AbstractHttp2StreamSourceChannel receiver = holder.sourceChannel;
if(receiver != null) {
IoUtils.safeClose(receiver);
Expand All @@ -1418,7 +1446,12 @@ private StreamHolder find(int streamId) {
}
} else break;
}
return streamHolders.get(streamId);
final StreamHolder holder = streamHolders.get(streamId);
if(holder != null && (!all && !holder.sent)) {
return null;
} else {
return holder;
}
}

private Map<Integer, StreamHolder> getStreamHolders() {
Expand Down
Loading

0 comments on commit 5749332

Please sign in to comment.