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

NettyHttpServerTest.testErrorBeforeRead handle exception #1848

Merged
merged 2 commits into from
Sep 29, 2021
Merged
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 @@ -584,12 +584,6 @@ void testSingleError(ExecutorSupplier clientExecutorSupplier,
void testErrorBeforeRead(ExecutorSupplier clientExecutorSupplier,
ExecutorSupplier serverExecutorSupplier) throws Exception {
setUp(clientExecutorSupplier, serverExecutorSupplier);
// Flaky test: https://github.com/apple/servicetalk/issues/245
ignoreTestWhen(IMMEDIATE, IMMEDIATE);
ignoreTestWhen(IMMEDIATE, CACHED);
ignoreTestWhen(CACHED, IMMEDIATE);
ignoreTestWhen(CACHED, CACHED);

final StreamingHttpRequest request = reqRespFactory.newRequest(GET, SVC_ERROR_BEFORE_READ).payloadBody(
getChunkPublisherFromStrings("Goodbye", "cruel", "world!"));

Expand All @@ -601,14 +595,22 @@ void testErrorBeforeRead(ExecutorSupplier clientExecutorSupplier,

final BlockingIterator<Buffer> httpPayloadChunks = response.payloadBody().toIterable().iterator();

Exception e = assertThrows(Exception.class, () -> httpPayloadChunks.next());
Exception e = assertThrows(Exception.class, httpPayloadChunks::next);
assertThat(e, either(instanceOf(RuntimeException.class)).or(instanceOf(ExecutionException.class)));
// Due to a race condition, the exception cause here can vary.
// If the socket closure is delayed slightly
// (for example, by delaying the Publisher.error(...) on the server)
// then the client throws ClosedChannelException. However if the socket closure happens quickly enough,
// the client throws NativeIoException (KQueue) or IOException (NIO).
assertThat(e.getCause(), instanceOf(IOException.class));
} catch (Throwable cause) {
// The server intentionally triggers an error when it writes, if this happens before all content is read
// the client may fail to write the request due to premature connection closure.
if (cause instanceof ExecutionException) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative approach can be to use "flushOnEnd" strategy by converting StreamingHttpRequest to an aggregated one and back. Then we don't need to worry about write failures on the client-side.
This approach also good. Either way is great to fix this test.

assertThat(cause.getCause(), instanceOf(IOException.class));
} else {
assertThat(cause, instanceOf(IOException.class));
}
} finally {
assertConnectionClosed();
}
Expand Down