-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix jetty 12.0.x transient timeouts (#10844)
Fixes #10234 * Introduced transient failures in reads where a failure chunk has last=false. * Transient failure now do not fail the handler callback. * Improve eeN ContentProducer to more carefully assert transient and terminal errors + enable HttpInputIntegrationTest * Do not add connection: close to the response when the error is transient * Rework ChunksContentSource to support null chunks * Added tests to verify the new transient failure cases * Review all code that handles failure, and handling correctly transient failure, either by making them fatal, and/or by failing Content.Source. Signed-off-by: Ludovic Orban <[email protected]> Signed-off-by: Olivier Lamy <[email protected]> Signed-off-by: Simone Bordet <[email protected]> Co-authored-by: Ludovic Orban <[email protected]> Co-authored-by: Olivier Lamy <[email protected]> Co-authored-by: Joakim Erdfelt <[email protected]> Co-authored-by: Chad Wilson <[email protected]> Co-authored-by: Simone Bordet <[email protected]>
- Loading branch information
1 parent
b9bd3f2
commit 7dcab84
Showing
67 changed files
with
3,732 additions
and
627 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/AsyncContentListenerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.client; | ||
|
||
import java.io.Closeable; | ||
import java.net.URI; | ||
import java.nio.ByteBuffer; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.eclipse.jetty.client.transport.HttpConversation; | ||
import org.eclipse.jetty.client.transport.HttpRequest; | ||
import org.eclipse.jetty.client.transport.HttpResponse; | ||
import org.eclipse.jetty.io.Content; | ||
import org.eclipse.jetty.io.content.ChunksContentSource; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.instanceOf; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class AsyncContentListenerTest | ||
{ | ||
@Test | ||
public void testTransientFailureBecomesTerminal() | ||
{ | ||
TestSource originalSource = new TestSource( | ||
Content.Chunk.from(ByteBuffer.wrap(new byte[] {1}), false), | ||
Content.Chunk.from(ByteBuffer.wrap(new byte[] {2}), false), | ||
Content.Chunk.from(new NumberFormatException(), false), | ||
Content.Chunk.from(ByteBuffer.wrap(new byte[] {3}), true) | ||
); | ||
|
||
List<Content.Chunk> collectedChunks = new ArrayList<>(); | ||
Response.AsyncContentListener asyncContentListener = (response, chunk, demander) -> | ||
{ | ||
chunk.retain(); | ||
collectedChunks.add(chunk); | ||
demander.run(); | ||
}; | ||
|
||
HttpResponse response = new HttpResponse(new HttpRequest(new HttpClient(), new HttpConversation(), URI.create("http://localhost"))); | ||
asyncContentListener.onContentSource(response, originalSource); | ||
|
||
assertThat(collectedChunks.size(), is(2)); | ||
assertThat(collectedChunks.get(0).isLast(), is(false)); | ||
assertThat(collectedChunks.get(0).getByteBuffer().get(), is((byte)1)); | ||
assertThat(collectedChunks.get(0).getByteBuffer().hasRemaining(), is(false)); | ||
assertThat(collectedChunks.get(1).isLast(), is(false)); | ||
assertThat(collectedChunks.get(1).getByteBuffer().get(), is((byte)2)); | ||
assertThat(collectedChunks.get(1).getByteBuffer().hasRemaining(), is(false)); | ||
|
||
Content.Chunk chunk = originalSource.read(); | ||
assertThat(Content.Chunk.isFailure(chunk, true), is(true)); | ||
assertThat(chunk.getFailure(), instanceOf(NumberFormatException.class)); | ||
|
||
collectedChunks.forEach(Content.Chunk::release); | ||
originalSource.close(); | ||
} | ||
|
||
private static class TestSource extends ChunksContentSource implements Closeable | ||
{ | ||
private Content.Chunk[] chunks; | ||
|
||
public TestSource(Content.Chunk... chunks) | ||
{ | ||
super(Arrays.asList(chunks)); | ||
this.chunks = chunks; | ||
} | ||
|
||
@Override | ||
public void close() | ||
{ | ||
if (chunks != null) | ||
{ | ||
for (Content.Chunk chunk : chunks) | ||
{ | ||
if (chunk != null) | ||
chunk.release(); | ||
} | ||
chunks = null; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.