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

feat: implement connection timeout functionality #4407

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat: implement connection timeout functionality #4407

wants to merge 1 commit into from

Conversation

romange
Copy link
Collaborator

@romange romange commented Jan 5, 2025

timeout argument shuts down idle connections after the specified time.

Fixes #1677

@romange romange force-pushed the Pr2 branch 4 times, most recently from f50e9dc to c09c45c Compare January 6, 2025 02:06
`timeout` argument shuts down idle connections after the specified time.

Fixes #1677

Signed-off-by: Roman Gershman <[email protected]>

ABSL_FLAG(uint32_t, interpreter_per_thread, 10, "Lua interpreters per thread");
ABSL_FLAG(uint32_t, timeout, 0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe rename to connection_timeout?

Copy link
Collaborator

Choose a reason for hiding this comment

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

do you intend to change the default in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the name and the default value are compatible with valkey. see https://github.com/valkey-io/valkey/blob/unstable/valkey.conf#L161

facade::Connection* dfly_conn = static_cast<facade::Connection*>(conn);
using Phase = facade::Connection::Phase;
auto phase = dfly_conn->phase();
if ((phase == Phase::READ_SOCKET || dfly_conn->IsSending()) &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the reason to close the connection if its in READ_SOCKET phase?
From what I understand this will also close replication incoming connections if the replication is not on admin port

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

closing idle connections in READ state is a desired behavior. You can check it with valkey by opening a connection with timeout=1 and run ping after a few seconds.

Having said that, good catch - we should exempt replication connections.

void ServerState::ConnectionsWatcherFb(util::ListenerInterface* main) {
while (true) {
util::fb2::NoOpLock noop;
if (watcher_cv_.wait_for(noop, 1s, [this] { return gstate_ == GlobalState::SHUTTING_DOWN; })) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

running this every second can be heavy if server has many connections

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agree. that's why I added a TODO:
https://github.com/dragonflydb/dragonfly/pull/4407/files#diff-6032993b813fa531ddc738b01203e65ded0d630c65a5de559a6772b98fac5951R258

in fact, newest version of helio already allows partial traversal. I will fix the TODO in this PR.

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.

Add timeout flag
2 participants