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

HTTPCLIENT-2301. Fix stale connection handling in BasicHttpClientConnectionManager #502

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

arturobernalg
Copy link
Member

@arturobernalg arturobernalg commented Nov 4, 2023

The key change involves using the local conn variable, obtained from internalEndpoint.detach(), to ensure we're acting on the correct connection instance.

@arturobernalg arturobernalg marked this pull request as ready for review November 4, 2023 18:42
@@ -357,7 +357,19 @@ ManagedHttpClientConnection getConnection(final HttpRoute route, final Object st
this.conn = this.connFactory.createConnection(null);
this.created = System.currentTimeMillis();
} else {
this.conn.activate();
// Check if the existing connection is stale
if (this.conn.isStale()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturobernalg Should not the connection have already been checked for staleness in #validate line 355? Why doing again? Am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not the connection have already been checked for staleness in #validate line 355? Why doing again? Am I missing something?

@ok2c
The staleness check was only being performed when the deadline had expired. In our case, the deadline wasn't expired, so the connection's staleness wasn't being evaluated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturobernalg Now I am confused. The #validate method performs the check only if the period of inactivity exceeds ValidateAfterInactivity setting. This is intentional and by design. One does not want to execute the stale check too often due to its cost and impact on performance. The change you are proposing seems to be breaking that. Is that really what you want? If one wants the stale check done every time one can set ValidateAfterInactivity to -1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon reviewing your comment, I realize that I overlooked the intentional design behind the validate method's frequency of execution I've committed a new potential fix this. I have now submitted a new commit that aims to rectify this. The updated code ensures that the connection being released is indeed the one that was detached from the InternalConnectionEndpoint. This should maintain the intended behavior while addressing the issue at hand.
While I have conducted extensive testing to validate this fix, I must admit that connection management is not my primary area of expertise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturobernalg There is no problem of what so ever. That is why we have reviews

@arturobernalg arturobernalg marked this pull request as draft November 6, 2023 20:16
@arturobernalg arturobernalg force-pushed the HTTPCLIENT-2301 branch 2 times, most recently from 70cf7d7 to 8c71081 Compare November 7, 2023 18:07
@arturobernalg arturobernalg marked this pull request as ready for review November 7, 2023 22:00
LOG.debug("{} Connection is not kept alive", id);
}
} else {
final boolean reusable = conn != null && conn.isOpen() && conn.isConsistent();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturobernalg The variable seems redundant. Looks OK otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

…This commit updates the release method to use the local conn variable from internalEndpoint.detach() for accurate state management and resource cleanup, addressing the issue HTTPCLIENT-2301.
@arturobernalg arturobernalg merged commit 6ac8946 into apache:5.4.x Nov 9, 2023
7 checks passed
ok2c pushed a commit that referenced this pull request Dec 13, 2023
…This commit updates the release method to use the local conn variable from internalEndpoint.detach() for accurate state management and resource cleanup, addressing the issue HTTPCLIENT-2301. (#502)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants