-
Notifications
You must be signed in to change notification settings - Fork 348
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
Changes from 2 commits
f87a81b
c66648c
0c2c722
1b2709a
4bd75b9
7247895
d243833
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,10 +56,11 @@ public class Http1Config { | |
private final int maxHeaderCount; | ||
private final int maxEmptyLineCount; | ||
private final int initialWindowSize; | ||
private final boolean useRstOnTimeout; | ||
|
||
Http1Config(final HttpVersion version, final int bufferSize, final int chunkSizeHint, | ||
final Timeout waitForContinueTimeout, final int maxLineLength, final int maxHeaderCount, | ||
final int maxEmptyLineCount, final int initialWindowSize) { | ||
final int maxEmptyLineCount, final int initialWindowSize, final boolean useRstOnTimeout) { | ||
super(); | ||
this.version = version; | ||
this.bufferSize = bufferSize; | ||
|
@@ -69,6 +70,7 @@ public class Http1Config { | |
this.maxHeaderCount = maxHeaderCount; | ||
this.maxEmptyLineCount = maxEmptyLineCount; | ||
this.initialWindowSize = initialWindowSize; | ||
this.useRstOnTimeout = useRstOnTimeout; | ||
} | ||
|
||
/** | ||
|
@@ -109,6 +111,13 @@ public int getInitialWindowSize() { | |
return initialWindowSize; | ||
} | ||
|
||
/** | ||
* @since 5.4 | ||
*/ | ||
public boolean getUseRstOnTimeout() { | ||
return useRstOnTimeout; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder builder = new StringBuilder(); | ||
|
@@ -120,6 +129,7 @@ public String toString() { | |
.append(", maxHeaderCount=").append(maxHeaderCount) | ||
.append(", maxEmptyLineCount=").append(maxEmptyLineCount) | ||
.append(", initialWindowSize=").append(initialWindowSize) | ||
.append(", useRstOnTimeout=").append(useRstOnTimeout) | ||
.append("]"); | ||
return builder.toString(); | ||
} | ||
|
@@ -147,6 +157,7 @@ public static Http1Config.Builder copy(final Http1Config config) { | |
private static final int INIT_MAX_HEADER_COUNT = -1; | ||
private static final int INIT_MAX_LINE_LENGTH = -1; | ||
private static final int INIT_MAX_EMPTY_LINE_COUNT = 10; | ||
private static final boolean USE_RST_ON_TIMEOUT = false; | ||
|
||
public static class Builder { | ||
|
||
|
@@ -158,6 +169,7 @@ public static class Builder { | |
private int maxHeaderCount; | ||
private int maxEmptyLineCount; | ||
private int initialWindowSize; | ||
private boolean userRstOnTimeout; | ||
|
||
Builder() { | ||
this.version = HttpVersion.HTTP_1_1; | ||
|
@@ -168,6 +180,7 @@ public static class Builder { | |
this.maxHeaderCount = INIT_MAX_HEADER_COUNT; | ||
this.maxEmptyLineCount = INIT_MAX_EMPTY_LINE_COUNT; | ||
this.initialWindowSize = INIT_WINDOW_SIZE; | ||
this.userRstOnTimeout = USE_RST_ON_TIMEOUT; | ||
} | ||
|
||
/** | ||
|
@@ -222,6 +235,14 @@ public Builder setInitialWindowSize(final int initialWindowSize) { | |
return this; | ||
} | ||
|
||
/** | ||
* @since 5.4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need a real Javadoc description that explains what this toggle does. |
||
*/ | ||
public Builder setUserRstOnTimeout(final boolean userRstOnTimeout) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ooeunz Please add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. Thanks. |
||
this.userRstOnTimeout = userRstOnTimeout; | ||
return this; | ||
} | ||
|
||
public Http1Config build() { | ||
return new Http1Config( | ||
version, | ||
|
@@ -231,7 +252,8 @@ public Http1Config build() { | |
maxLineLength, | ||
maxHeaderCount, | ||
maxEmptyLineCount, | ||
initialWindowSize); | ||
initialWindowSize, | ||
userRstOnTimeout); | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -212,7 +213,11 @@ public ClassicHttpResponse execute( | |
return response; | ||
|
||
} catch (final HttpException | IOException | RuntimeException ex) { | ||
Closer.closeQuietly(conn); | ||
ok2c marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (http1Config.getUseRstOnTimeout()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a use case for keeping the old behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @garydgregory Graceful shutdown of TLS connections would be one. One can drop a TLS connection without a @ooeunz Why do not we always use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To maintain backward compatibility, the existing behavior has been preserved. However, if it is determined that there are no issues with backward compatibility, I would like to make immediate close the default behavior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that a socket timeout indicates that the server is not functioning properly, so setting immediate close as the default behavior should not cause any issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TY @ok2c for the explanation. I think details like this should be in the Javadoc for the getter-setter pair. |
||
Closer.close(conn, CloseMode.IMMEDIATE); | ||
} else { | ||
Closer.closeQuietly(conn); | ||
} | ||
throw ex; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ooeunz Please add
@since 5.4
tag