-
Notifications
You must be signed in to change notification settings - Fork 567
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
Connection cache 100 continue #9795
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: David Kral <[email protected]>
Signed-off-by: David Kral <[email protected]>
Signed-off-by: David Kral <[email protected]>
Signed-off-by: David Kral <[email protected]>
Signed-off-by: David Kral <[email protected]>
copyright updated Signed-off-by: David Kral <[email protected]>
this.upstream = upstream; | ||
this.idleTimeoutIterations = (int) (idleTimout.toMillis() / TIMEOUT); | ||
this.lastIterationRemainder = (int) (idleTimout.toMillis() % TIMEOUT); |
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.
After looking at the final version of this, I think there's no need for the "remainder" logic TBH. Timeouts are approximations (especially at the socket layer), so it should be enough to divide by TIMEOUT or maybe add 1 to that. No need for finer control than that. That should simplify your logic a bit, making it easier to read.
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.
+1 the loop should just increment until max iterations
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.
Something like this maybe ?
Should the idle "tick" timeout (500) be configurable ?
If both are configurable then it's up to the user to pick multiple numbers.
maxIterations = (int) Math.ceilDiv(Math.max(1, idleTimout.getSeconds()), 500);
// idleTimout=0 -> maxIterations=1
// idleTimout=499 -> maxIterations=1
// idleTimout=501 -> maxIterations=2
// idleTimout=999 -> maxIterations=2
try {
int timeout = -1; // always at least one iteration
for (int i = 0; i < maxIterations && !cancelled; i++) {
try {
int t = socket.getSoTimeout();
if (t != 500) {
timeout = t;
}
socket.setSoTimeout(500);
next = upstream.read();
if (next <= 0) {
closed = true;
// no need to restore timeout
return;
}
// sucessful read
break;
} catch (SocketTimeoutException ignored) {
// ignore socket timeout, retry until maxIterations
}
}
// restore original timeout
// read sucessful, canceled (endIdle) or max iterations (idle timeout)
socket.setSoTimeout(timeout);
} catch (IOException e) {
closed = true;
throw new UncheckedIOException(e);
}
Description
Fixes ##9736
This issue introduces a new way of idle connection handling. It splits the desired idle timeout and uses small 500 ms timeouts until the overall desired timeout is reached. This helps to interrupt the idle timeout mechanism.
FYI: I will add some more comments to the code
Documentation
None