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

Connection cache 100 continue #9795

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Verdent
Copy link
Member

@Verdent Verdent commented Feb 13, 2025

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

Signed-off-by: David Kral <[email protected]>
Signed-off-by: David Kral <[email protected]>
@Verdent Verdent added the 4.x Version 4.x label Feb 13, 2025
@Verdent Verdent self-assigned this Feb 13, 2025
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Feb 13, 2025
@barchetta barchetta mentioned this pull request Feb 13, 2025
16 tasks
copyright updated

Signed-off-by: David Kral <[email protected]>
this.upstream = upstream;
this.idleTimeoutIterations = (int) (idleTimout.toMillis() / TIMEOUT);
this.lastIterationRemainder = (int) (idleTimout.toMillis() % TIMEOUT);
Copy link
Member

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.

Copy link
Contributor

@romain-grecourt romain-grecourt Feb 14, 2025

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

Copy link
Contributor

@romain-grecourt romain-grecourt Feb 14, 2025

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants