Skip to content

in_stdin: support stdin plugin on windows#11821

Open
cosmo0920 wants to merge 2 commits into
masterfrom
cosmo0920-support-stdin-on-windows
Open

in_stdin: support stdin plugin on windows#11821
cosmo0920 wants to merge 2 commits into
masterfrom
cosmo0920-support-stdin-on-windows

Conversation

@cosmo0920
Copy link
Copy Markdown
Contributor

@cosmo0920 cosmo0920 commented May 19, 2026

On Windows, it's a bit of works needed to support in_stdin capability.
In this PR, we're finally enabling a capability to handle stdin on Windows.

Closes #11120.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
cmd> echo {"message":"Hey"} | .\bin\fluent-bit -i stdin -ostdout -v
  • Debug log output from testing the change
Fluent Bit v5.0.6
* Copyright (C) 2015-2026 The Fluent Bit Authors
* Fluent Bit is a CNCF graduated project under the Fluent organization
* https://fluentbit.io

______ _                  _    ______ _ _           _____  _____
|  ___| |                | |   | ___ (_) |         |  ___||  _  |
| |_  | |_   _  ___ _ __ | |_  | |_/ /_| |_  __   _|___ \ | |/' |
|  _| | | | | |/ _ \ '_ \| __| | ___ \ | __| \ \ / /   \ \|  /| |
| |   | | |_| |  __/ | | | |_  | |_/ / | |_   \ V //\__/ /\ |_/ /
\_|   |_|\__,_|\___|_| |_|\__| \____/|_|\__|   \_/ \____(_)\___/


[2026/05/19 16:54:58.246] [ info] Configuration:
[2026/05/19 16:54:58.246] [ info]  flush time     | 1.000000 seconds
[2026/05/19 16:54:58.246] [ info]  grace          | 5 seconds
[2026/05/19 16:54:58.246] [ info]  daemon         | 0
[2026/05/19 16:54:58.246] [ info] ___________
[2026/05/19 16:54:58.246] [ info]  inputs:
[2026/05/19 16:54:58.246] [ info]      stdin
[2026/05/19 16:54:58.246] [ info] ___________
[2026/05/19 16:54:58.246] [ info]  filters:
[2026/05/19 16:54:58.246] [ info] ___________
[2026/05/19 16:54:58.246] [ info]  outputs:
[2026/05/19 16:54:58.246] [ info]      stdout.0
[2026/05/19 16:54:58.246] [ info] ___________
[2026/05/19 16:54:58.246] [ info]  collectors:
[2026/05/19 16:54:58.248] [ info] [fluent bit] version=5.0.6, commit=6474297f3d, pid=40488
[2026/05/19 16:54:58.248] [debug] [engine] maxstdio set: 512
[2026/05/19 16:54:58.248] [debug] [engine] coroutine stack size: 98302 bytes (96.0K)
[2026/05/19 16:54:58.248] [ info] [storage] ver=1.5.4, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2026/05/19 16:54:58.248] [ info] [simd    ] disabled
[2026/05/19 16:54:58.248] [ info] [cmetrics] version=2.1.3
[2026/05/19 16:54:58.248] [ info] [ctraces ] version=0.7.1
[2026/05/19 16:54:58.248] [ info] [input:stdin:stdin.0] initializing
[2026/05/19 16:54:58.248] [ info] [input:stdin:stdin.0] storage_strategy='memory' (memory only)
[2026/05/19 16:54:58.248] [debug] [stdin:stdin.0] created event channels: read=816 write=820
[2026/05/19 16:54:58.248] [debug] [input:stdin:stdin.0] buf_size=16000
[2026/05/19 16:54:58.248] [debug] [stdout:stdout.0] created event channels: read=828 write=832
[2026/05/19 16:54:58.249] [ info] [sp] stream processor started
[2026/05/19 16:54:58.250] [ info] [output:stdout:stdout.0] worker #0 started
[2026/05/19 16:54:58.250] [ info] [engine] Shutdown Grace Period=5, Shutdown Input Grace Period=2
[2026/05/19 16:54:59.255] [debug] [task] created task=0000016C430621D0 id=0 OK
[2026/05/19 16:54:59.255] [debug] [output:stdout:stdout.0] task_id=0 assigned to thread #0
[0] stdin.0: [[1779177298.351077800, {}], {"message"=>"Hey"}]
[2026/05/19 16:54:59.256] [debug] [out flush] cb_destroy coro_id=0
[2026/05/19 16:54:59.256] [debug] [task] destroy task=0000016C430621D0 (task_id=0)
[2026/05/19 16:55:02] [engine] caught signal (SIGINT)
[2026/05/19 16:55:02.280] [ warn] [engine] service will shutdown in max 5 seconds
[2026/05/19 16:55:02.280] [ info] [engine] pausing all inputs..
[2026/05/19 16:55:03.292] [ info] [engine] service has stopped (0 pending tasks)
[2026/05/19 16:55:03.292] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2026/05/19 16:55:03.292] [ info] [output:stdout:stdout.0] thread worker #0 stopped
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

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

  • Bug Fixes

    • Improved Windows compatibility and reliability for the standard-input plugin, fixing edge cases when reading from pipes and consoles to prevent unexpected exits or hangs.
  • Behavior Change

    • Enabled standard-input as a default input on Windows to provide consistent, predictable stdin handling out of the box.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

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: eba412fc-28be-46d7-ba12-9ac98a2b638e

📥 Commits

Reviewing files that changed from the base of the PR and between 183f5e4 and cc05a58.

📒 Files selected for processing (3)
  • cmake/windows-setup.cmake
  • plugins/in_stdin/in_stdin.c
  • plugins/in_stdin/in_stdin.h
✅ Files skipped from review due to trivial changes (1)
  • cmake/windows-setup.cmake
🚧 Files skipped from review as they are similar to previous changes (2)
  • plugins/in_stdin/in_stdin.h
  • plugins/in_stdin/in_stdin.c

📝 Walkthrough

Walkthrough

The PR enables the stdin input plugin on Windows and adds Windows-specific stdin handling: Win32 includes and constants, availability/read wrappers using PeekNamedPipe/_kbhit, platform-aware fd duplication and cleanup, and time-based collector polling on Windows. CMake default enables the plugin for Windows.

Changes

Windows stdin input plugin support

Layer / File(s) Summary
Data structures and Windows constants
plugins/in_stdin/in_stdin.h
Header adds Windows includes, FLB_STDIN_WIN32_COLLECT_NSEC polling constant, and stdin_handle/stdin_type struct fields to track Windows stdin state.
Windows I/O implementation and collection integration
plugins/in_stdin/in_stdin.c
Adds Windows-only includes; implements stdin_win32_available() (PeekNamedPipe/_kbhit) and stdin_read() wrapper; updates in_stdin_collect() to use the wrapper and treat zero-byte pipe reads specially on Windows.
Initialization and Windows stdin handle acquisition
plugins/in_stdin/in_stdin.c
Initialize ctx->fd = -1; on Windows capture GetStdHandle()/GetFileType() and duplicate stdin with _dup(_fileno(stdin)); non-Windows retains dup(STDIN_FILENO).
Collector registration and polling strategy
plugins/in_stdin/in_stdin.c
Windows registers time-based polling via FLB_STDIN_WIN32_COLLECT_NSEC; non-Windows continues using an event-based collector monitoring ctx->fd.
Error handling and resource cleanup
plugins/in_stdin/in_stdin.c
Use _close() on Windows (and close() elsewhere) for ctx->fd in init error paths and in_stdin_exit(), guarded by ctx->fd >= 0.
Build configuration
cmake/windows-setup.cmake
Enable FLB_IN_STDIN input plugin when FLB_WINDOWS_DEFAULTS is set (change default from No to Yes).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Suggested reviewers

  • edsiper

Poem

🐰 On Windows I hop with care,
I peek the pipe and sniff the air,
Console keys or streams that flow,
Time polls tap to make things go,
Stdin sings — the rabbit knows to share.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 accurately and concisely describes the main change: enabling Windows support for the stdin input plugin.
Linked Issues check ✅ Passed The PR fully addresses the linked issue #11120 by implementing Windows support for the stdin plugin with proper runtime handling and build configuration.
Out of Scope Changes check ✅ Passed All changes are directly related to enabling stdin plugin support on Windows; no unrelated or extraneous modifications were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cosmo0920-support-stdin-on-windows

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 and usage tips.

@cosmo0920 cosmo0920 added this to the Fluent Bit v5.1 milestone May 19, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 183f5e4156

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plugins/in_stdin/in_stdin.c
cosmo0920 added 2 commits June 1, 2026 15:50
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-required ok-package-test Run PR packaging tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows support for stdin plugin

2 participants