Skip to content

Comments

Add send_keepalive_packet option to out_forward plugin#5262

Open
2ZZ wants to merge 1 commit intofluent:masterfrom
2ZZ:add-tcp-keepalive-to-out-forward
Open

Add send_keepalive_packet option to out_forward plugin#5262
2ZZ wants to merge 1 commit intofluent:masterfrom
2ZZ:add-tcp-keepalive-to-out-forward

Conversation

@2ZZ
Copy link
Contributor

@2ZZ 2ZZ commented Feb 18, 2026

Which issue(s) this PR fixes:
Fixes #

What this PR does / why we need it:

This PR adds the send_keepalive_packet configuration parameter to the out_forward plugin to enable TCP keepalive (SO_KEEPALIVE) on forward output connections.

Background:
The existing keepalive parameter only enables connection pooling/reuse, not TCP-level keepalive probes. This can lead to accumulation of dead connections in CLOSE-WAIT state.

Changes:

  • Added send_keepalive_packet config parameter (default: false)
  • Pass the parameter to both socket_create_tcp and socket_create_tls calls
  • Added tests to verify the parameter works correctly

Related:
This follows the same pattern as #2352 which added the same feature to in_forward.

Docs Changes:

Release Note:

  • out_forward: Add send_keepalive_packet option

@Watson1978
Copy link
Contributor

@2ZZ Can you add DCO sign in your commit and fix tests ?

@2ZZ 2ZZ force-pushed the add-tcp-keepalive-to-out-forward branch 2 times, most recently from 7b60a69 to 2c5860d Compare February 19, 2026 09:39
@2ZZ
Copy link
Contributor Author

2ZZ commented Feb 19, 2026

@2ZZ Can you add DCO sign in your commit and fix tests ?

Fixed and signed.

One test failed but it doesn't look related to my change (https://github.com/fluent/fluentd/actions/runs/22176445014/job/64126271546?pr=5262#step:6:5177)

Copy link
Contributor

@Watson1978 Watson1978 left a comment

Choose a reason for hiding this comment

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

I think send_keepalive_packet should only be set to true when keepalive is set to true.

Like:

if @send_keepalive_packet && @deny_keepalive
raise Fluent::ConfigError, "both 'send_keepalive_packet' and 'deny_keepalive' cannot be set to true"
end

Can you fix this and add tests for that, like following ?

test 'both send_keepalive_packet and deny_keepalive cannot be enabled' do
assert_raise(Fluent::ConfigError.new("both 'send_keepalive_packet' and 'deny_keepalive' cannot be set to true")) do
create_driver(config_auth + %[
send_keepalive_packet true
deny_keepalive true
])
end
end

@Watson1978 Watson1978 added this to the v1.20.0 milestone Feb 20, 2026
This adds the send_keepalive_packet configuration parameter to enable
TCP keepalive (SO_KEEPALIVE) on forward output connections, similar to
the implementation in in_forward (PR fluent#2352).

The existing 'keepalive' parameter only enables connection pooling,
not TCP-level keepalive probes.

Signed-off-by: Ian Driver <idriver@williamhill.us>
@2ZZ 2ZZ force-pushed the add-tcp-keepalive-to-out-forward branch from 2c5860d to c8b647a Compare February 20, 2026 09:41
@2ZZ
Copy link
Contributor Author

2ZZ commented Feb 20, 2026

I think send_keepalive_packet should only be set to true when keepalive is set to true.

Like:

if @send_keepalive_packet && @deny_keepalive
raise Fluent::ConfigError, "both 'send_keepalive_packet' and 'deny_keepalive' cannot be set to true"
end

Can you fix this and add tests for that, like following ?

test 'both send_keepalive_packet and deny_keepalive cannot be enabled' do
assert_raise(Fluent::ConfigError.new("both 'send_keepalive_packet' and 'deny_keepalive' cannot be set to true")) do
create_driver(config_auth + %[
send_keepalive_packet true
deny_keepalive true
])
end
end

Makes sense, updated now & tests passed

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