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

Optimize connection close logic to resolve timeout delay issue #508

Merged
merged 7 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -54,6 +54,7 @@
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.io.CloseMode;
import org.apache.hc.core5.io.Closer;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Timeout;
Expand Down Expand Up @@ -212,7 +213,7 @@ public ClassicHttpResponse execute(
return response;

} catch (final HttpException | IOException | RuntimeException ex) {
Closer.closeQuietly(conn);
ok2c marked this conversation as resolved.
Show resolved Hide resolved
Closer.close(conn, CloseMode.IMMEDIATE);
throw ex;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package org.apache.hc.core5.http.impl.io;

import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.List;

import org.apache.hc.core5.http.ClassicHttpRequest;
Expand All @@ -37,12 +38,14 @@
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.Method;
import org.apache.hc.core5.http.config.Http1Config;
import org.apache.hc.core5.http.io.HttpClientConnection;
import org.apache.hc.core5.http.io.HttpResponseInformationCallback;
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.io.CloseMode;
import org.apache.hc.core5.util.Timeout;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -402,7 +405,7 @@ void testExecutionIOException() throws Exception {

Mockito.doThrow(new IOException("Oopsie")).when(conn).sendRequestHeader(request);
Assertions.assertThrows(IOException.class, () -> executor.execute(request, conn, context));
Mockito.verify(conn).close();
Mockito.verify(conn).close(CloseMode.IMMEDIATE);
}

@Test
Expand All @@ -415,7 +418,7 @@ void testExecutionRuntimeException() throws Exception {

Mockito.doThrow(new RuntimeException("Oopsie")).when(conn).receiveResponseHeader();
Assertions.assertThrows(RuntimeException.class, () -> executor.execute(request, conn, context));
Mockito.verify(conn).close();
Mockito.verify(conn).close(CloseMode.IMMEDIATE);
}

}
Loading