Skip to content

input: set FLB_IO_TCP_KA flag in flb_input_upstream_set - #12096

Open
labros-mediaalpha wants to merge 1 commit into
fluent:masterfrom
labros-mediaalpha:fix/flb-input-upstream-set-ka-flag
Open

input: set FLB_IO_TCP_KA flag in flb_input_upstream_set#12096
labros-mediaalpha wants to merge 1 commit into
fluent:masterfrom
labros-mediaalpha:fix/flb-input-upstream-set-ka-flag

Conversation

@labros-mediaalpha

@labros-mediaalpha labros-mediaalpha commented Jul 13, 2026

Copy link
Copy Markdown

This PR description was AI-assisted (Claude Code).

What does this PR do?

flb_input_upstream_set() copies net.* config into the upstream's
net_setup struct, but never sets the FLB_IO_TCP_KA stream flag that
flb_upstream_conn_get() actually checks when deciding a new
connection's initial recycle state. This mirrors the equivalent, already
correct logic in flb_output_upstream_set().

Companion PR (#12095) adds the missing flb_input_upstream_set() call
to in_prometheus_scrape; neither PR alone restores connection reuse —
verified empirically, see #12094.

Impact

Affects every input plugin calling flb_input_upstream_set():
currently in_prometheus_scrape (companion PR), in_kubernetes_events,
and in_calyptia_fleet. The latter two were not independently
re-tested against this fix — flagging for maintainer visibility since
their existing "fix" may not have been fully effective either.

Testing

Verified via -vv debug logging and tcpdump packet capture on a live
v5.0.7 instance: without this fix, in_prometheus_scrape connections
are torn down and recreated every scrape cycle even with net.keepalive
on and the companion PR's upstream_set() call in place. With this fix,
connections are created once and recycled on subsequent scrapes.

Ref #12094

Summary by CodeRabbit

  • Bug Fixes
    • Improved TCP connection reliability by consistently applying keepalive settings when initializing upstream connections.
    • Ensures configured keepalive behavior is honored for input connections.

flb_upstream_conn_get() derives a new connection's initial recycle
state from flb_stream_is_keepalive(), which checks the FLB_IO_TCP_KA
stream flag -- not net.keepalive directly. flb_output_upstream_set()
sets this flag from ins->net_setup.keepalive; flb_input_upstream_set()
did not, so connections for any input plugin using this function never
recycled regardless of net.keepalive.

Mirrors the existing logic in flb_output_upstream_set() (src/flb_output.c).

This likely affects in_kubernetes_events and in_calyptia_fleet as well,
since they call flb_input_upstream_set() too -- not independently
verified, worth re-testing.

Ref fluent#12094

Signed-off-by: Labros Chaidas <labros@mediaalpha.com>
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 419e822c-a5ce-414b-bb3d-e7d65f622687

📥 Commits

Reviewing files that changed from the base of the PR and between 5c5b8ce and a799075.

📒 Files selected for processing (1)
  • src/flb_input.c

📝 Walkthrough

Walkthrough

Input upstream setup now enables the FLB_IO_TCP_KA stream flag when net.keepalive is configured, aligning input behavior with output upstream initialization.

Changes

Input upstream keepalive

Layer / File(s) Summary
Apply keepalive during upstream setup
src/flb_input.c
flb_input_upstream_set() enables FLB_IO_TCP_KA on the upstream base when input keepalive is enabled.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related issues

Suggested reviewers: edsiper, cosmo0920, edbingo, niedbalski, pwhelan

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main code change in flb_input_upstream_set.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant