Skip to content

Conversation

edsiper
Copy link
Member

@edsiper edsiper commented Aug 30, 2025

This PR implements timeouts for the full http response and for read idle timeouts.

It also extends HTTP output plugin with the new property http.response_timeout to set the maximum duration of a response (for slow servers), the default is 60s.


Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • New Features
    • Added configurable HTTP timeouts: response_timeout (default 60s) and read_idle_timeout (default 0s) for the HTTP output.
    • Enforces per-request limits: stops waiting when total response time or idle read time exceed configured thresholds.
    • Emits clear error messages when timeouts are reached to aid troubleshooting.
    • New client-level options enable finer control and improved resilience with slow or unresponsive endpoints.

Copy link

coderabbitai bot commented Aug 30, 2025

Walkthrough

Adds response and read-idle timeout support: new timestamp and timeout fields in the public HTTP client struct, two public setter APIs, initialization of timestamps on request, enforcement of response and read-idle timeouts in the response read loop, and plugin config wiring to set per-request timeouts.

Changes

Cohort / File(s) Summary
HTTP client public API
include/fluent-bit/flb_http_client.h
Adds ts_start and last_read_ts (time_t) and response_timeout and read_idle_timeout (int) to struct flb_http_client; includes <time.h>; declares flb_http_set_read_idle_timeout and flb_http_set_response_timeout.
HTTP client core logic
src/flb_http_client.c
Implements the two timeout setter functions; initializes ts_start and last_read_ts when sending requests; in the response read loop checks elapsed time against response_timeout and read_idle_timeout, updates last_read_ts on successful reads, and returns errors on timeout.
out_http plugin config & usage
plugins/out_http/http.c, plugins/out_http/http.h, plugins/out_http/http_conf.h
Adds response_timeout (default 60s) and read_idle_timeout (default 0s) fields to struct flb_out_http and config_map options http.response_timeout and http.read_idle_timeout; sets client timeouts per request using plugin-configured values (or io_timeout fallback for read idle).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Plugin as out_http
  participant Client as flb_http_client
  participant Server as HTTP Server

  Plugin->>Client: create client
  Plugin->>Client: flb_http_set_response_timeout(timeout)
  Plugin->>Client: flb_http_set_read_idle_timeout(timeout)
  Plugin->>Client: flb_http_do_request(...)
  Client->>Server: send HTTP request

  rect rgba(230,240,255,0.5)
    note over Client: initialize ts_start, last_read_ts
    loop read response
      Server-->>Client: data chunk / EOF
      alt data received
        Client->>Client: update last_read_ts
      else no data
        Client->>Client: if now - ts_start > response_timeout => error
        Client->>Client: if now - last_read_ts > read_idle_timeout => error
      end
    end
  end

  Client-->>Plugin: response complete / error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I count the ticks while nibbling logs at night,
If bytes go quiet, I spring to set things right.
A timeout thump, a hop, a tiny debug frown—
I keep the streams from lingering down.
Quick paws, keen clock, I guard each packet's flight.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b84219b and 15fdfc2.

📒 Files selected for processing (1)
  • src/flb_http_client.c (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/flb_http_client.c
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-centos-7
  • GitHub Check: PR - fuzzing test
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch http-client-timeouts

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (6)
plugins/out_http/http.h (1)

97-99: Field added is fine; document units and disable semantics

Consider clarifying in a comment that the value is seconds and that 0 disables the timeout. If you expect larger ranges, prefer uint32_t or time_t over int.

plugins/out_http/http.c (1)

684-688: Config key added — clarify behavior

Good default. Suggest updating the description to mention units and that 0 disables the timeout, e.g., “Maximum time (in seconds) to wait for a server response; set to 0 to disable.”

include/fluent-bit/flb_http_client.h (1)

249-255: State and timeout fields — consider monotonic time

Storing timestamps as time_t is fine, but wall-clock jumps can skew calculations. If feasible, switch to a monotonic clock source for ts_start/last_read_ts (e.g., CLOCK_MONOTONIC) or note the caveat in comments.

src/flb_http_client.c (3)

47-47: Prefer a monotonic clock for timeout logic

time(NULL) is wall clock and can jump. If available, prefer a monotonic source (e.g., clock_gettime(CLOCK_MONOTONIC)) for timeout checks to avoid false positives/negatives.


1503-1515: On timeout, recycle the connection to avoid reusing a bad socket

When a response/read idle timeout triggers, the connection likely isn’t reusable. Recycle it before returning error so it doesn’t re-enter the keepalive pool.

Apply this diff:

-        if (c->response_timeout > 0 &&
-            (now - c->ts_start) > c->response_timeout) {
-            flb_error("[http_client] response timeout reached");
-            return FLB_HTTP_ERROR;
-        }
+        if (c->response_timeout > 0 &&
+            (now - c->ts_start) > c->response_timeout) {
+            flb_error("[http_client] response timeout reached");
+            flb_upstream_conn_recycle(c->u_conn, FLB_FALSE);
+            return FLB_HTTP_ERROR;
+        }
@@
-        if (c->read_idle_timeout > 0 &&
-            (now - c->last_read_ts) > c->read_idle_timeout) {
-            flb_error("[http_client] read idle timeout reached");
-            return FLB_HTTP_ERROR;
-        }
+        if (c->read_idle_timeout > 0 &&
+            (now - c->last_read_ts) > c->read_idle_timeout) {
+            flb_error("[http_client] read idle timeout reached");
+            flb_upstream_conn_recycle(c->u_conn, FLB_FALSE);
+            return FLB_HTTP_ERROR;
+        }

1531-1534: Update last_read_ts with a fresh timestamp

Use a fresh timestamp after the read completes to avoid skew if the read blocked.

-            if (r_bytes > 0) {
-                c->last_read_ts = now;
-            }
+            if (r_bytes > 0) {
+                c->last_read_ts = time(NULL);
+            }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7445e38 and f45a19d.

📒 Files selected for processing (4)
  • include/fluent-bit/flb_http_client.h (3 hunks)
  • plugins/out_http/http.c (2 hunks)
  • plugins/out_http/http.h (1 hunks)
  • src/flb_http_client.c (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
include/fluent-bit/flb_http_client.h (1)
src/flb_http_client.c (2)
  • flb_http_set_read_idle_timeout (1143-1147)
  • flb_http_set_response_timeout (1149-1153)
plugins/out_http/http.c (1)
src/flb_http_client.c (2)
  • flb_http_set_response_timeout (1149-1153)
  • flb_http_set_read_idle_timeout (1143-1147)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: PR - fuzzing test
  • GitHub Check: pr-compile-centos-7
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
🔇 Additional comments (5)
plugins/out_http/http.c (1)

196-198: Per-request timeouts initialization — LGTM

Setting response_timeout from ctx and read_idle_timeout from net.io_timeout is appropriate and keeps behavior consistent with existing net settings.

include/fluent-bit/flb_http_client.h (2)

30-30: Include time.h — LGTM


384-386: New setter prototypes — LGTM

src/flb_http_client.c (2)

1143-1153: Setter implementations — LGTM


1433-1436: Initialize timeout tracking — LGTM

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
plugins/out_http/http.c (1)

686-688: Fix user-facing typo in option description.

“paylod” → “payload”.

Apply this diff:

-     "Specify if the response paylod should be logged or not"
+     "Specify if the response payload should be logged or not"
🧹 Nitpick comments (1)
plugins/out_http/http.c (1)

198-204: Simplify idle-timeout selection and add a helpful debug trace.

Minor cleanup to avoid duplication and make observability easier during support.

Apply this diff:

-    if (ctx->read_idle_timeout > 0) {
-        flb_http_set_read_idle_timeout(c, ctx->read_idle_timeout);
-    }
-    else {
-        flb_http_set_read_idle_timeout(c, ctx->ins->net_setup.io_timeout);
-    }
+    {
+        int idle_timeout = (ctx->read_idle_timeout > 0)
+                           ? ctx->read_idle_timeout
+                           : ctx->ins->net_setup.io_timeout;
+
+        flb_http_set_read_idle_timeout(c, idle_timeout);
+        flb_plg_debug(ctx->ins,
+                      "http timeouts: response=%ds, read_idle=%ds",
+                      ctx->response_timeout, idle_timeout);
+    }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f45a19d and 369b421.

📒 Files selected for processing (2)
  • plugins/out_http/http.c (2 hunks)
  • plugins/out_http/http.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/out_http/http.h
🧰 Additional context used
🧬 Code graph analysis (1)
plugins/out_http/http.c (1)
src/flb_http_client.c (2)
  • flb_http_set_response_timeout (1149-1153)
  • flb_http_set_read_idle_timeout (1143-1147)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: PR - fuzzing test
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-centos-7
🔇 Additional comments (1)
plugins/out_http/http.c (1)

196-197: Good use of per-request timeouts on the HTTP client.

Setting the response timeout right after client creation is correct and maps cleanly to the new API.

Comment on lines +690 to +699
{
FLB_CONFIG_MAP_TIME, "http.response_timeout", "60s",
0, FLB_TRUE, offsetof(struct flb_out_http, response_timeout),
"Set maximum time to wait for a server response"
},
{
FLB_CONFIG_MAP_TIME, "http.read_idle_timeout", "0s",
0, FLB_TRUE, offsetof(struct flb_out_http, read_idle_timeout),
"Set maximum allowed time between two consecutive reads"
},
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Clarify option descriptions to spell out behavior and defaults.

Tighten phrasing and document the fallback to net.io_timeout for read idle.

Apply this diff:

-    {
-     FLB_CONFIG_MAP_TIME, "http.response_timeout", "60s",
-     0, FLB_TRUE, offsetof(struct flb_out_http, response_timeout),
-     "Set maximum time to wait for a server response"
-    },
+    {
+     FLB_CONFIG_MAP_TIME, "http.response_timeout", "60s",
+     0, FLB_TRUE, offsetof(struct flb_out_http, response_timeout),
+     "Maximum time to wait for the server response (status/headers). Default: 60s"
+    },
-    {
-     FLB_CONFIG_MAP_TIME, "http.read_idle_timeout", "0s",
-     0, FLB_TRUE, offsetof(struct flb_out_http, read_idle_timeout),
-     "Set maximum allowed time between two consecutive reads"
-    },
+    {
+     FLB_CONFIG_MAP_TIME, "http.read_idle_timeout", "0s",
+     0, FLB_TRUE, offsetof(struct flb_out_http, read_idle_timeout),
+     "Maximum allowed idle time between consecutive socket reads; if 0s, falls back to net.io_timeout; set >0 to override"
+    },

To ensure docs/examples are in sync, run:


🏁 Script executed:

#!/bin/bash
# Verify references and docs for the new options
rg -n -C2 -g '!**/build/**' -g '!**/dist/**' $'http\\.response_timeout|http\\.read_idle_timeout'

Length of output: 768


Update documentation for http.response_timeout and http.read_idle_timeout
The new descriptions in plugins/out_http/http.c aren’t reflected in any docs or examples—no matches outside the C code. Please update the corresponding documentation (e.g. docs/plugins/out_http.md or your examples) to include the revised option texts and defaults.

🤖 Prompt for AI Agents
In plugins/out_http/http.c around lines 690-699, the config map descriptions for
http.response_timeout and http.read_idle_timeout were changed but the
documentation/examples were not updated; update docs/plugins/out_http.md (and
any example configs) to add these two options, include the exact option names,
their revised descriptions ("Set maximum time to wait for a server response"
with default 60s for http.response_timeout; "Set maximum allowed time between
two consecutive reads" with default 0s for http.read_idle_timeout), and ensure
the config reference table and any example config snippets reflect the new
defaults and wording.

}
available = flb_http_buffer_available(c) - 1;
}
time_t now = time(NULL);
Copy link
Contributor

@cosmo0920 cosmo0920 Sep 1, 2025

Choose a reason for hiding this comment

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

Nits: Do we need to define this variable on top of this function?
Just for confirming to follow our coding guideline.

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch :)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
plugins/out_http/http.c (1)

690-699: Clarify option descriptions and document fallback behavior

Tighten phrasing and explicitly mention defaults and the read-idle fallback to net.io_timeout.

-    {
-     FLB_CONFIG_MAP_TIME, "http.response_timeout", "60s",
-     0, FLB_TRUE, offsetof(struct flb_out_http, response_timeout),
-     "Set maximum time to wait for a server response"
-    },
+    {
+     FLB_CONFIG_MAP_TIME, "http.response_timeout", "60s",
+     0, FLB_TRUE, offsetof(struct flb_out_http, response_timeout),
+     "Maximum time to wait for the server response (status/headers). Default: 60s"
+    },
-    {
-     FLB_CONFIG_MAP_TIME, "http.read_idle_timeout", "0s",
-     0, FLB_TRUE, offsetof(struct flb_out_http, read_idle_timeout),
-     "Set maximum allowed time between two consecutive reads"
-    },
+    {
+     FLB_CONFIG_MAP_TIME, "http.read_idle_timeout", "0s",
+     0, FLB_TRUE, offsetof(struct flb_out_http, read_idle_timeout),
+     "Maximum allowed idle time between consecutive socket reads; if 0s, falls back to net.io_timeout; set >0 to override"
+    },

Also update user docs/examples to include these options and descriptions (label docs-required). I can draft the docs snippet if you want.

🧹 Nitpick comments (3)
src/flb_http_client.c (2)

47-47: Prefer a monotonic clock for timeout tracking

Using time(NULL) is wall-clock and can jump (NTP, manual changes). For robust timeouts, use CLOCK_MONOTONIC when available, falling back to time(NULL).

Apply within existing spots:

@@
-#include <time.h>
+#include <time.h>

And at initialization/read sites (see further diffs below).


1143-1147: Clamp negative timeout inputs

Defensive check avoids unintended negative values from future callers or mis-parsed config.

 int flb_http_set_read_idle_timeout(struct flb_http_client *c, int timeout)
 {
-    c->read_idle_timeout = timeout;
+    if (timeout < 0) {
+        timeout = 0;
+    }
+    c->read_idle_timeout = timeout;
     return 0;
 }
 
 int flb_http_set_response_timeout(struct flb_http_client *c, int timeout)
 {
-    c->response_timeout = timeout;
+    if (timeout < 0) {
+        timeout = 0;
+    }
+    c->response_timeout = timeout;
     return 0;
 }

Also applies to: 1149-1153

plugins/out_http/http.c (1)

196-204: Good: per-request timeout wiring with sensible fallback

Wires response_timeout directly and read_idle_timeout with a fallback to net.io_timeout. Consider adding a debug line to log the resolved values to aid support.

     c->cb_ctx = ctx->ins->callback;
 
     flb_http_set_response_timeout(c, ctx->response_timeout);
 
     if (ctx->read_idle_timeout > 0) {
         flb_http_set_read_idle_timeout(c, ctx->read_idle_timeout);
     }
     else {
         flb_http_set_read_idle_timeout(c, ctx->ins->net_setup.io_timeout);
     }
+    flb_plg_debug(ctx->ins, "timeouts: response=%ds, read_idle=%ds (resolved)",
+                  ctx->response_timeout,
+                  (ctx->read_idle_timeout > 0) ? ctx->read_idle_timeout
+                                               : ctx->ins->net_setup.io_timeout);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 369b421 and b84219b.

📒 Files selected for processing (4)
  • include/fluent-bit/flb_http_client.h (3 hunks)
  • plugins/out_http/http.c (2 hunks)
  • plugins/out_http/http.h (1 hunks)
  • src/flb_http_client.c (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • include/fluent-bit/flb_http_client.h
  • plugins/out_http/http.h
🧰 Additional context used
🧬 Code graph analysis (1)
plugins/out_http/http.c (1)
src/flb_http_client.c (2)
  • flb_http_set_response_timeout (1149-1153)
  • flb_http_set_read_idle_timeout (1143-1147)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-centos-7
  • GitHub Check: PR - fuzzing test
🔇 Additional comments (1)
src/flb_http_client.c (1)

1433-1436: Time fields and timeout units verified
ts_start and last_read_ts are declared as time_t, and response_timeout/read_idle_timeout are ints (seconds), matching their comparisons; no changes required.

Comment on lines +1433 to +1436
/* Initialize timeout tracking */
c->ts_start = time(NULL);
c->last_read_ts = c->ts_start;

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use CLOCK_MONOTONIC for timeout measurements

Prevents false positives/negatives if the system clock changes. Keeps your compare logic intact.

@@ int flb_http_do_request(struct flb_http_client *c, size_t *bytes)
-    /* Initialize timeout tracking */
-    c->ts_start = time(NULL);
-    c->last_read_ts = c->ts_start;
+    /* Initialize timeout tracking */
+#if defined(CLOCK_MONOTONIC)
+    {
+        struct timespec ts;
+        clock_gettime(CLOCK_MONOTONIC, &ts);
+        c->ts_start = (time_t) ts.tv_sec;
+        c->last_read_ts = c->ts_start;
+    }
+#else
+    c->ts_start = time(NULL);
+    c->last_read_ts = c->ts_start;
+#endif
@@ int flb_http_get_response_data(struct flb_http_client *c, size_t bytes_consumed)
-    time_t now;
+    time_t now;
+    struct timespec ts;
@@
-        now = time(NULL);
+        /* monotonic time for timeouts */
+#if defined(CLOCK_MONOTONIC)
+        clock_gettime(CLOCK_MONOTONIC, &ts);
+        now = (time_t) ts.tv_sec;
+#else
+        now = time(NULL);
+#endif
@@
-            if (r_bytes > 0) {
-                c->last_read_ts = now;
-            }
+            if (r_bytes > 0) {
+                c->last_read_ts = now;
+            }

Also applies to: 1504-1504, 1460-1461, 1532-1535

🤖 Prompt for AI Agents
In src/flb_http_client.c around lines 1433-1436 (and also apply to lines
~1460-1461, 1504, and 1532-1535), the code initializes timeout timestamps using
time(NULL); replace these uses of the system clock with CLOCK_MONOTONIC-based
time measurements: use clock_gettime(CLOCK_MONOTONIC, &ts) to obtain a monotonic
timespec, convert to a consistent integer/float representation (e.g., seconds or
milliseconds) and assign to c->ts_start and c->last_read_ts (and any other
timeout timestamp variables), and update any comparisons to use the same
monotonic representation so timeout checks are immune to system clock changes.

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.

2 participants