-
Notifications
You must be signed in to change notification settings - Fork 816
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
Avoid the issue of connections not being released. #2915
Merged
kenhuuu
merged 1 commit into
apache:master
from
dh-cloud:fix-20241125-ConnectionsKeepAlive
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hello @dh-cloud, thanks for noticing this issue with potential resource leaks in the gremlin-server.
In the master branch we have switched to HTTP (away from web sockets in 3.7) which means there will be much more short term connections compared to web sockets which uses long lived connections. When there is decreased activity we should aim to release the resources and thus not use the keep alive option to keep the connection active.
There is still an issue with potential resource leak but instead we can fix this using the existing
idleConnectionTimeout
setting. The issue here is that during the switch from web sockets to HTTP, we neglected to enable idle connection monitoring for HTTP 😢 . What do you think about changing this PR to enable idle connection monitoring instead?See below for references in the code as to what I'm referring to:
tinkerpop/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
Line 167 in 56c72f6
tinkerpop/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Channelizer.java
Line 52 in 56c72f6
tinkerpop/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java
Line 144 in 56c72f6
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.
@andreachild
Yes, I agree that we can also add handling for idle connections, but the original intention of this PR was to destroy broken connections, especially in scenarios like the following: when a client establishes a long connection with the gremlin-server, and then the client's network card is suddenly unplugged to simulate a client-side network issue. In this case, when the server uses netstat -antp to check, the connection still appears to be established, but using the ping command to test the client's address fails, and this connection will never be destroyed. I have reproduced this scenario.
Feel free to let me know if you need any further adjustments!
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.
I agree we should protect the server against broken connections. My concern would be that enabling the
SO_KEEPALIVE
could interfere with the idle connection handling if it is enabled and keep connections alive which should be considered idle and cleaned up. TheSO_KEEPALIVE
settings are OS-dependent so it would be vary by OS when keep alive pings would kick in and how often it would be sent.For example assuming we fix
HttpChannelizer
to return true forboolean supportsIdleMonitor()
andSettings.idleConnectionTimeout
is 30 seconds and the OS is configured to start sending keep alive pings after 10 seconds every 1 second:What do you think about one of the following solutions:
SO_KEEPALIVE
to be enabled only if idle connection detection is disabledMy preference would be the latter option as it would allow consistent control of the timeouts at the application level instead of relying on the varying OS-level settings.
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.
I have fully understood your point. For the requirement to disconnect abnormal connections, I believe we can consider it from two dimensions:
When boolean supportsIdleMonitor() is false, i.e., idle connection detection is disabled, we can enable SO_KEEPALIVE as a fallback to prevent broken connections from remaining occupied.
When supportsIdleMonitor() is true, we need to improve the handling logic for idle timeout connections.
In the TinkerPop master source code, I noticed that settings.idleConnectionTimeout and settings.keepAliveInterval are both default to 0. As a result, the new IdleStateHandler in AbstractChannelizer.class will not have any effect.
Setting specific values for idleConnectionTimeout and keepAliveInterval is a complex task and has significant impact, as they control the idle threshold for idle connections. However, different use cases have different requirements, and it is challenging to provide a one-size-fits-all recommendation.
For this PR, I force pushed new commit implementing the fallback measure only when boolean supportsIdleMonitor() is false.
I hope this helps! If you need any further adjustments, feel free to let me know.