-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
input: fix crash caused by incorrectly initializing input coroutine params. #7982
base: master
Are you sure you want to change the base?
Conversation
…ers. Signed-off-by: Phillip Whelan <[email protected]>
Signed-off-by: Phillip Whelan <[email protected]>
Signed-off-by: Phillip Whelan <[email protected]>
Signed-off-by: Phillip Whelan <[email protected]>
Here is a valgrind log: valgrind --leak-check=full ./bin/fluent-bit -c ke.conf
==600057== Memcheck, a memory error detector
==600057== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==600057== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==600057== Command: ./bin/fluent-bit -c ke.conf
==600057==
Fluent Bit v2.1.10
* Copyright (C) 2015-2022 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io
[2023/09/27 10:44:11] [ info] [fluent bit] version=2.1.10, commit=19a8a3056e, pid=600057
[2023/09/27 10:44:11] [ info] [storage] ver=1.5.1, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/09/27 10:44:11] [ info] [input:kubernetes_events:kubernetes_events.0] API server: http://127.0.0.1:8000
[2023/09/27 10:44:11] [ info] [input:kubernetes_events:kubernetes_events.1] API server: http://127.0.0.1:8000
[2023/09/27 10:44:11] [ info] [cmetrics] version=0.6.3
[2023/09/27 10:44:11] [ info] [input:kubernetes_events:kubernetes_events.2] API server: http://127.0.0.1:8000
[2023/09/27 10:44:11] [ info] [ctraces ] version=0.3.1
[2023/09/27 10:44:11] [ info] [output:stdout:stdout.0] worker #0 started
[2023/09/27 10:44:11] [ info] [input:kubernetes_events:kubernetes_events.0] initializing
[2023/09/27 10:44:11] [ info] [input:kubernetes_events:kubernetes_events.0] storage_strategy='memory' (memory only)
[2023/09/27 10:44:11] [ info] [input:kubernetes_events:kubernetes_events.0] thread instance initialized
[2023/09/27 10:44:11] [ info] [input:kubernetes_events:kubernetes_events.1] initializing
[2023/09/27 10:44:11] [ info] [input:kubernetes_events:kubernetes_events.1] storage_strategy='memory' (memory only)
[2023/09/27 10:44:11] [ info] [input:kubernetes_events:kubernetes_events.1] thread instance initialized
[2023/09/27 10:44:11] [ info] [input:kubernetes_events:kubernetes_events.2] initializing
[2023/09/27 10:44:11] [ info] [input:kubernetes_events:kubernetes_events.2] storage_strategy='memory' (memory only)
[2023/09/27 10:44:11] [ info] [input:kubernetes_events:kubernetes_events.2] thread instance initialized
[2023/09/27 10:44:11] [ info] [sp] stream processor started
[2023/09/27 10:44:11] [ warn] [input:kubernetes_events:kubernetes_events.1] cannot open ./kube.token.txt
[2023/09/27 10:44:11] [error] [input:kubernetes_events:kubernetes_events.1] failed to refresh token
[2023/09/27 10:44:11] [ warn] [input:kubernetes_events:kubernetes_events.0] cannot open ./kube.token.txt
[2023/09/27 10:44:11] [error] [input:kubernetes_events:kubernetes_events.0] failed to refresh token
[2023/09/27 10:44:11] [ warn] [input:kubernetes_events:kubernetes_events.2] cannot open ./kube.token.txt
[2023/09/27 10:44:11] [error] [input:kubernetes_events:kubernetes_events.2] failed to refresh token
[2023/09/27 10:44:12] [ warn] [input:kubernetes_events:kubernetes_events.0] cannot open ./kube.token.txt
[2023/09/27 10:44:12] [error] [input:kubernetes_events:kubernetes_events.0] failed to refresh token
[2023/09/27 10:44:12] [ warn] [input:kubernetes_events:kubernetes_events.2] cannot open ./kube.token.txt
[2023/09/27 10:44:12] [error] [input:kubernetes_events:kubernetes_events.2] failed to refresh token
[2023/09/27 10:44:12] [ warn] [input:kubernetes_events:kubernetes_events.1] cannot open ./kube.token.txt
[2023/09/27 10:44:12] [error] [input:kubernetes_events:kubernetes_events.1] failed to refresh token
[2023/09/27 10:44:12] [ warn] [input:kubernetes_events:kubernetes_events.2] cannot open ./kube.token.txt
[2023/09/27 10:44:12] [error] [input:kubernetes_events:kubernetes_events.2] failed to refresh token
[2023/09/27 10:44:12] [ warn] [input:kubernetes_events:kubernetes_events.0] cannot open ./kube.token.txt
[2023/09/27 10:44:12] [ warn] [input:kubernetes_events:kubernetes_events.1] cannot open ./kube.token.txt
[2023/09/27 10:44:12] [error] [input:kubernetes_events:kubernetes_events.0] failed to refresh token
[2023/09/27 10:44:12] [error] [input:kubernetes_events:kubernetes_events.1] failed to refresh token
[2023/09/27 10:44:13] [ warn] [input:kubernetes_events:kubernetes_events.2] cannot open ./kube.token.txt
[2023/09/27 10:44:13] [error] [input:kubernetes_events:kubernetes_events.2] failed to refresh token
[2023/09/27 10:44:13] [ warn] [input:kubernetes_events:kubernetes_events.1] cannot open ./kube.token.txt
[2023/09/27 10:44:13] [error] [input:kubernetes_events:kubernetes_events.1] failed to refresh token
[2023/09/27 10:44:13] [ warn] [input:kubernetes_events:kubernetes_events.0] cannot open ./kube.token.txt
[2023/09/27 10:44:13] [error] [input:kubernetes_events:kubernetes_events.0] failed to refresh token
[2023/09/27 10:44:13] [ warn] [input:kubernetes_events:kubernetes_events.0] cannot open ./kube.token.txt
[2023/09/27 10:44:13] [error] [input:kubernetes_events:kubernetes_events.0] failed to refresh token
[2023/09/27 10:44:13] [ warn] [input:kubernetes_events:kubernetes_events.1] cannot open ./kube.token.txt
[2023/09/27 10:44:13] [ warn] [input:kubernetes_events:kubernetes_events.2] cannot open ./kube.token.txt
[2023/09/27 10:44:13] [error] [input:kubernetes_events:kubernetes_events.1] failed to refresh token
[2023/09/27 10:44:13] [error] [input:kubernetes_events:kubernetes_events.2] failed to refresh token
[2023/09/27 10:44:14] [ warn] [input:kubernetes_events:kubernetes_events.1] cannot open ./kube.token.txt
[2023/09/27 10:44:14] [error] [input:kubernetes_events:kubernetes_events.1] failed to refresh token
[2023/09/27 10:44:14] [ warn] [input:kubernetes_events:kubernetes_events.0] cannot open ./kube.token.txt
[2023/09/27 10:44:14] [error] [input:kubernetes_events:kubernetes_events.0] failed to refresh token
[2023/09/27 10:44:14] [ warn] [input:kubernetes_events:kubernetes_events.2] cannot open ./kube.token.txt
[2023/09/27 10:44:14] [error] [input:kubernetes_events:kubernetes_events.2] failed to refresh token
[2023/09/27 10:44:14] [ warn] [input:kubernetes_events:kubernetes_events.1] cannot open ./kube.token.txt
[2023/09/27 10:44:14] [error] [input:kubernetes_events:kubernetes_events.1] failed to refresh token
[2023/09/27 10:44:14] [ warn] [input:kubernetes_events:kubernetes_events.2] cannot open ./kube.token.txt
[2023/09/27 10:44:14] [ warn] [input:kubernetes_events:kubernetes_events.0] cannot open ./kube.token.txt
[2023/09/27 10:44:14] [error] [input:kubernetes_events:kubernetes_events.2] failed to refresh token
[2023/09/27 10:44:14] [error] [input:kubernetes_events:kubernetes_events.0] failed to refresh token
[2023/09/27 10:44:15] [ warn] [input:kubernetes_events:kubernetes_events.1] cannot open ./kube.token.txt
[2023/09/27 10:44:15] [error] [input:kubernetes_events:kubernetes_events.1] failed to refresh token
[2023/09/27 10:44:15] [ warn] [input:kubernetes_events:kubernetes_events.2] cannot open ./kube.token.txt
[2023/09/27 10:44:15] [error] [input:kubernetes_events:kubernetes_events.2] failed to refresh token
[2023/09/27 10:44:15] [ warn] [input:kubernetes_events:kubernetes_events.0] cannot open ./kube.token.txt
[2023/09/27 10:44:15] [error] [input:kubernetes_events:kubernetes_events.0] failed to refresh token
[2023/09/27 10:44:15] [ warn] [input:kubernetes_events:kubernetes_events.1] cannot open ./kube.token.txt
[2023/09/27 10:44:15] [error] [input:kubernetes_events:kubernetes_events.1] failed to refresh token
[2023/09/27 10:44:15] [ warn] [input:kubernetes_events:kubernetes_events.0] cannot open ./kube.token.txt
[2023/09/27 10:44:15] [error] [input:kubernetes_events:kubernetes_events.0] failed to refresh token
[2023/09/27 10:44:15] [ warn] [input:kubernetes_events:kubernetes_events.2] cannot open ./kube.token.txt
[2023/09/27 10:44:15] [error] [input:kubernetes_events:kubernetes_events.2] failed to refresh token
[2023/09/27 10:44:16] [ warn] [input:kubernetes_events:kubernetes_events.1] cannot open ./kube.token.txt
[2023/09/27 10:44:16] [error] [input:kubernetes_events:kubernetes_events.1] failed to refresh token
[2023/09/27 10:44:16] [ warn] [input:kubernetes_events:kubernetes_events.2] cannot open ./kube.token.txt
[2023/09/27 10:44:16] [error] [input:kubernetes_events:kubernetes_events.2] failed to refresh token
[2023/09/27 10:44:16] [ warn] [input:kubernetes_events:kubernetes_events.0] cannot open ./kube.token.txt
[2023/09/27 10:44:16] [error] [input:kubernetes_events:kubernetes_events.0] failed to refresh token
[2023/09/27 10:44:16] [ warn] [input:kubernetes_events:kubernetes_events.0] cannot open ./kube.token.txt
[2023/09/27 10:44:16] [error] [input:kubernetes_events:kubernetes_events.0] failed to refresh token
[2023/09/27 10:44:16] [ warn] [input:kubernetes_events:kubernetes_events.1] cannot open ./kube.token.txt
[2023/09/27 10:44:16] [error] [input:kubernetes_events:kubernetes_events.1] failed to refresh token
[2023/09/27 10:44:16] [ warn] [input:kubernetes_events:kubernetes_events.2] cannot open ./kube.token.txt
[2023/09/27 10:44:16] [error] [input:kubernetes_events:kubernetes_events.2] failed to refresh token
^C[2023/09/27 10:44:16] [engine] caught signal (SIGINT)
[2023/09/27 10:44:16] [ warn] [engine] service will shutdown in max 5 seconds
[2023/09/27 10:44:16] [ info] [engine] service has stopped (0 pending tasks)
[2023/09/27 10:44:17] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2023/09/27 10:44:17] [ info] [output:stdout:stdout.0] thread worker #0 stopped
[2023/09/27 10:44:17] [ warn] [input:kubernetes_events:kubernetes_events.1] cannot open ./kube.token.txt
[2023/09/27 10:44:17] [ warn] [input:kubernetes_events:kubernetes_events.2] cannot open ./kube.token.txt
[2023/09/27 10:44:17] [error] [input:kubernetes_events:kubernetes_events.2] failed to refresh token
[2023/09/27 10:44:17] [ warn] [input:kubernetes_events:kubernetes_events.0] cannot open ./kube.token.txt
[2023/09/27 10:44:17] [error] [input:kubernetes_events:kubernetes_events.1] failed to refresh token
[2023/09/27 10:44:17] [error] [input:kubernetes_events:kubernetes_events.0] failed to refresh token
==600057==
==600057== HEAP SUMMARY:
==600057== in use at exit: 0 bytes in 0 blocks
==600057== total heap usage: 3,551 allocs, 3,551 frees, 4,874,153 bytes allocated
==600057==
==600057== All heap blocks were freed -- no leaks are possible
==600057==
==600057== For lists of detected and suppressed errors, rerun with: -s
==600057== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) This was run with the following fluent-bit configuration: [INPUT]
name kubernetes_events
tag k8s_events.*
kube_retention_time 5m
kube_request_limit 100
kube_namespace tenant-svc
kube_token_file ./kube.token.txt
threaded on
kube_url http://127.0.0.1:8000
[INPUT]
name kubernetes_events
tag k8s_events.*
kube_retention_time 5m
kube_request_limit 100
kube_namespace platform-svc
kube_token_file ./kube.token.txt
threaded on
kube_url http://127.0.0.1:8000
[INPUT]
name kubernetes_events
tag k8s_events.*
kube_retention_time 5m
kube_request_limit 100
kube_namespace timeseries-svc
kube_token_file ./kube.token.txt
threaded on
kube_url http://127.0.0.1:8000
[OUTPUT]
Name stdout
Match *
Format json_lines It was also tested with similar results with all of the inputs with |
…/flb_input_exit. Signed-off-by: Phillip Whelan <[email protected]>
I ran the code with the health input plugin (which uses input coroutines) and ran it under valgrind, by default, with threaded and threaded off:
|
Set coroutine parameters to NULL for input and output via their initializers. Signed-off-by: Phillip Whelan <[email protected]>
I was finally able to fix the test on macos. It required calling the initialization functions for both input and output. |
Summary
Refactor the
flb_input
coroutine parameters to follow the same pattern asflb_output
and use the FLB_TLS set of macros.This is not only to standardize the code but to fix a bug where fluent-bit can crash when using input coroutines. Input coroutines can initialize fast enough to reset the libco key which leads to a
NULL
dereference ininput_pre_cb_collect
leading to a crash inco_switch
.Issues
This fixes a bug found in #7954.
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:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
ok-package-test
label to test for all targets (requires maintainer to do).Documentation
Backporting
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.