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

Prevents the connection from being used immediately when WriteTimeoutException occurs. #5738

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -329,6 +329,10 @@ private void fail(Throwable cause) {
}

final void failAndReset(Throwable cause) {
// Mark the session as unhealthy so that subsequent requests do not use it.
final HttpSession session = HttpSession.get(ch);
session.deactivate();
ikhoon marked this conversation as resolved.
Show resolved Hide resolved

if (cause instanceof ProxyConnectException || cause instanceof ResponseCompleteException) {
// - ProxyConnectException is handled by HttpSessionHandler.exceptionCaught().
// - ResponseCompleteException means the response is successfully received.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

package com.linecorp.armeria.client;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.util.concurrent.CompletionException;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -29,6 +32,8 @@
import com.linecorp.armeria.common.RequestHeaders;
import com.linecorp.armeria.common.RequestHeadersBuilder;
import com.linecorp.armeria.common.SessionProtocol;
import com.linecorp.armeria.common.logging.RequestLog;
import com.linecorp.armeria.internal.client.HttpSession;
import com.linecorp.armeria.server.Route;
import com.linecorp.armeria.server.ServerBuilder;
import com.linecorp.armeria.testing.junit5.server.ServerExtension;
Expand Down Expand Up @@ -63,12 +68,20 @@ void testWriteTimeout() {
headersBuilder.add("header1", Strings.repeat("a", 2048)); // set a header over 1KB

// using h1c since http2 compresses headers
assertThatThrownBy(() -> WebClient.builder(SessionProtocol.H1C, server.httpEndpoint())
.factory(clientFactory)
.writeTimeoutMillis(1000)
.build()
.blocking()
.execute(headersBuilder.build(), "content"))
.isInstanceOf(WriteTimeoutException.class);
try (ClientRequestContextCaptor captor = Clients.newContextCaptor()) {
final HttpResponse res = WebClient.builder(SessionProtocol.H1C, server.httpEndpoint())
.factory(clientFactory)
.writeTimeoutMillis(1000)
.build()
.execute(headersBuilder.build(), "content");
final ClientRequestContext ctx = captor.get();
assertThatThrownBy(() -> res.aggregate().join())
.isInstanceOf(CompletionException.class)
.hasCauseInstanceOf(WriteTimeoutException.class);

final RequestLog log = ctx.log().whenComplete().join();
// Make sure that the session is deactivated after the write timeout.
assertThat(HttpSession.get(log.channel()).isAcquirable()).isFalse();
}
}
}
Loading