Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macos: core: macOS coroutine unstability fixes #7820

Merged
merged 2 commits into from
Aug 22, 2023

Conversation

cosmo0920
Copy link
Contributor

In macOS, the size of pthread stack min of Intel Mac (x64) and Apple Silicon (M1/M2) is smaller than the Linux one.
This means that the concrete values are:

Intel Mac

PTHREAD_STACK_MIN = 8192
(3 * PTHREAD_STACK_MIN) / 2 = 12288 which means fluent-bit's minimum stack size

Apple Silicon

PTHREAD_STACK_MIN = 16384
(3 * PTHREAD_STACK_MIN) / 2 = 24576 which means fluent-bit's minimum stack size

They shouldn't be enough for libresolv API which needs to use heap memories: res_ninit(statep).

When increasing the coroutine size to:

24576 bytes (24KiB) on Intel Mac and 36864 bytes (36KiB) on Apple Silicon respectively, the heap memory corruptions are not occurred.

Related to #7670.

additional contexts

I tested for the minimum code:

#include <stdio.h>
#include <limits.h>

#ifdef FLB_CORO_STACK_SIZE
#define FLB_CORO_STACK_SIZE_BYTE      FLB_CORO_STACK_SIZE
#else
#define FLB_CORO_STACK_SIZE_BYTE      ((3 * PTHREAD_STACK_MIN) / 2)
#endif

int main(void)
{
    unsigned int size = FLB_CORO_STACK_SIZE_BYTE;

    printf("pthread stack min size = %u\n", PTHREAD_STACK_MIN);

    size = (size + 1023) & ~1023;
    printf("flb stack size = %u\n", size);

    return 0;
}

The canary CI results are:
https://github.com/fluent/fluent-bit/actions/runs/5832454631
https://github.com/fluent/fluent-bit/actions/runs/5832456028
https://github.com/fluent/fluent-bit/actions/runs/5832457491


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.

This is because the default size of pthread stack is 12K which size is
half of the Linux one.

Signed-off-by: Hiroshi Hatake <[email protected]>
@cosmo0920 cosmo0920 temporarily deployed to pr August 11, 2023 13:45 — with GitHub Actions Inactive
@cosmo0920 cosmo0920 temporarily deployed to pr August 11, 2023 13:45 — with GitHub Actions Inactive
@cosmo0920 cosmo0920 temporarily deployed to pr August 11, 2023 13:45 — with GitHub Actions Inactive
@cosmo0920 cosmo0920 temporarily deployed to pr August 11, 2023 14:14 — with GitHub Actions Inactive
@leonardo-albertovich leonardo-albertovich marked this pull request as ready for review August 11, 2023 16:57
@edsiper edsiper merged commit 4498a6b into master Aug 22, 2023
43 checks passed
@edsiper edsiper deleted the cosmo0920-macos-coro-unstability-fix branch August 22, 2023 10:47
@MrPibody7 MrPibody7 added this to the Fluent Bit v2.1.9 milestone Aug 29, 2023
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.

4 participants