Skip to content

Conversation

@cosmo0920
Copy link
Contributor

@cosmo0920 cosmo0920 commented Sep 24, 2025

In Windows, we need to initialize Winsock2 stack before using.

This is common failure for uninitialized error for Winsock2 stack.


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
  • Debug log output from testing the change
  • 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

  • Tests
    • Improved Windows compatibility for network-related tests by properly initializing and cleaning up the Windows networking stack during setup/teardown.
    • Reduces flaky behavior and increases stability on Windows machines and CI environments.
    • Enhances cross-platform consistency of test execution without altering runtime behavior of the application.
    • No changes to public interfaces or user-facing functionality.

In Windows, we need to initialize Winsock2 stack before using.

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
@coderabbitai
Copy link

coderabbitai bot commented Sep 24, 2025

Walkthrough

Introduces Windows-specific Winsock initialization and cleanup in tests/internal/processor.c by including flb_compat.h, invoking WSAStartup before network usage, and calling WSACleanup during teardown. No public interfaces changed.

Changes

Cohort / File(s) Summary
Tests: Windows Winsock setup/teardown
tests/internal/processor.c
Added flb_compat.h; under _WIN32, perform WSAStartup(MAKEWORD(2,2), &wsa) before network operations and WSACleanup() during teardown in processor test flows; no changes to exported/public APIs.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant TR as Test Runner
  participant PT as Processor Test
  participant WS as Winsock (Windows)
  participant SUT as Processor Logic

  TR->>PT: Start test
  alt Windows (_WIN32)
    PT->>WS: WSAStartup(2.2)
    WS-->>PT: Result
    note right of PT: Abort on failure
  end
  PT->>SUT: Initialize and run main loop
  SUT-->>PT: Execution completes
  alt Windows (_WIN32)
    PT->>WS: WSACleanup()
  end
  PT-->>TR: Report result
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

ok-package-test

Suggested reviewers

  • edsiper
  • koleini
  • fujimotos

Poem

I nudge the sockets, hop by hop,
WSA awake—pop, pop!
Tests now greet Windows with cheer,
Startup, cleanup, crystal clear.
Thump goes my paw: all tidy, done—
Carrots for CI, another run! 🥕🐇

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately summarizes the primary change—ensuring Winsock2 is initialized for processor tests on Windows—and includes clear scope labels ("processor: internal: tests") that help reviewers quickly understand context; it is specific and avoids vague language. The phrasing is concise and directly related to the changes described in the PR. This makes the title appropriate for the changeset.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cosmo0920-ensure-winsock2-stack-is-initialized

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

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 (2)
tests/internal/processor.c (2)

140-145: Winsock init is correct; add early-return with diagnostic on failure (optional)

Improves debuggability and avoids proceeding after failed init.

 #ifdef _WIN32
     WSADATA wsa;
     int wret = WSAStartup(MAKEWORD(2,2), &wsa);
     TEST_CHECK(wret == 0);
+    if (wret != 0) {
+        TEST_MSG("WSAStartup failed (rc=%d)", wret);
+        return;
+    }
 #endif

193-197: Guard WSACleanup so it only runs after successful WSAStartup

Prevents WSACleanup when init failed.

 #ifdef _WIN32
-    WSACleanup();
+    if (wret == 0) {
+        WSACleanup();
+    }
 #endif
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75a517b and 2f1b941.

📒 Files selected for processing (1)
  • tests/internal/processor.c (3 hunks)
⏰ 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: PR - fuzzing test
  • 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, clang, clang++)
  • 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, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 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_SIMD=On, 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_SANITIZE_MEMORY=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_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=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_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 (-DFLB_SMALL=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, gcc, g++)
  • 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-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-24.04, clang-14)
  • 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, gcc, g++, ubuntu-22.04, clang-12)
🔇 Additional comments (1)
tests/internal/processor.c (1)

31-31: Header inclusion OK — flb_compat.h provides winsock2; verify ws2tcpip and ws2_32 linkage for the test target

flb_compat.h (include/fluent-bit/flb_compat.h) includes <winsock2.h> (lines ~39–41) but not <ws2tcpip.h>; the repo contains many ws2_32 link entries (e.g. src/CMakeLists.txt:282) but I couldn't find a CMake target referencing tests/internal/processor.c — ensure the test target explicitly links ws2_32 and add <ws2tcpip.h> where the test needs it.

@edsiper edsiper merged commit b13d9d4 into master Sep 24, 2025
82 of 83 checks passed
@edsiper edsiper deleted the cosmo0920-ensure-winsock2-stack-is-initialized branch September 24, 2025 13:21
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.

3 participants