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

in_docker: fix error handling if some resources not found #5189

Merged
merged 1 commit into from
Apr 26, 2022

Conversation

nokute78
Copy link
Collaborator

This patch is to add NULL check to prevent SIGSEGV which is reported at #5149


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.

Documentation

  • [N/A] Documentation required for this feature

Backporting

  • [N/A] Backport to latest stable release.

Configuration

  1. Run a container.
  2. sudo fluent-bit -i docker -o stdout

Debug log

I tested renaming invalid cpu resource file name.

diff --git a/plugins/in_docker/docker.h b/plugins/in_docker/docker.h
index 98a9a94ed..317264d7d 100644
--- a/plugins/in_docker/docker.h
+++ b/plugins/in_docker/docker.h
@@ -35,7 +35,7 @@
 #define DOCKER_CGROUP_CPU_DIR "/sys/fs/cgroup/cpu/docker"
 #define DOCKER_MEM_LIMIT_FILE "memory.limit_in_bytes"
 #define DOCKER_MEM_USAGE_FILE "memory.usage_in_bytes"
-#define DOCKER_CPU_USAGE_FILE "cpuacct.usage"
+#define DOCKER_CPU_USAGE_FILE "cpuacct.usagd"
 #define DOCKER_LIB_ROOT       "/var/lib/docker/containers"
 #define DOCKER_CONFIG_JSON    "config.v2.json"
 #define DOCKER_NAME_ARG       "\"Name\""

No SIGSEGVs.

$ sudo bin/fluent-bit -i docker -o stdout
Fluent Bit v1.9.1
* Copyright (C) 2015-2021 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2022/03/26 09:09:06] [ info] [fluent bit] version=1.9.1, commit=1b89b4711b, pid=37257
[2022/03/26 09:09:06] [ info] [storage] version=1.1.6, type=memory-only, sync=normal, checksum=disabled, max_chunks_up=128
[2022/03/26 09:09:06] [ info] [cmetrics] version=0.3.0
[2022/03/26 09:09:06] [ info] [sp] stream processor started
[2022/03/26 09:09:06] [ info] [output:stdout:stdout.0] worker #0 started
[2022/03/26 09:09:07] [error] [plugins/in_docker/docker.c:315 errno=2] No such file or directory
[2022/03/26 09:09:07] [error] [input:docker:docker.0] error gathering CPU data from /sys/fs/cgroup/cpu/docker/58c33a47212e777cafb7014e44aa6c829b09a62f5f7e3aa316fd5c5144bce2be/cpuacct.usagd
[2022/03/26 09:09:08] [error] [plugins/in_docker/docker.c:315 errno=2] No such file or directory
[2022/03/26 09:09:08] [error] [input:docker:docker.0] error gathering CPU data from /sys/fs/cgroup/cpu/docker/58c33a47212e777cafb7014e44aa6c829b09a62f5f7e3aa316fd5c5144bce2be/cpuacct.usagd
[2022/03/26 09:09:09] [error] [plugins/in_docker/docker.c:315 errno=2] No such file or directory
[2022/03/26 09:09:09] [error] [input:docker:docker.0] error gathering CPU data from /sys/fs/cgroup/cpu/docker/58c33a47212e777cafb7014e44aa6c829b09a62f5f7e3aa316fd5c5144bce2be/cpuacct.usagd
^C[2022/03/26 09:09:09] [engine] caught signal (SIGINT)
[2022/03/26 09:09:09] [ info] [input] pausing docker.0
[2022/03/26 09:09:09] [ warn] [engine] service will shutdown in max 5 seconds
[2022/03/26 09:09:10] [ info] [engine] service has stopped (0 pending tasks)
[2022/03/26 09:09:10] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2022/03/26 09:09:10] [ info] [output:stdout:stdout.0] thread worker #0 stopped

Valgrind output

$ sudo valgrind --leak-check=full bin/fluent-bit -i docker -o stdout
==37262== Memcheck, a memory error detector
==37262== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==37262== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==37262== Command: bin/fluent-bit -i docker -o stdout
==37262== 
Fluent Bit v1.9.1
* Copyright (C) 2015-2021 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2022/03/26 09:09:44] [ info] [fluent bit] version=1.9.1, commit=1b89b4711b, pid=37262
[2022/03/26 09:09:44] [ info] [storage] version=1.1.6, type=memory-only, sync=normal, checksum=disabled, max_chunks_up=128
[2022/03/26 09:09:44] [ info] [cmetrics] version=0.3.0
[2022/03/26 09:09:44] [ info] [sp] stream processor started
[2022/03/26 09:09:44] [ info] [output:stdout:stdout.0] worker #0 started
[2022/03/26 09:09:45] [error] [plugins/in_docker/docker.c:315 errno=2] No such file or directory
[2022/03/26 09:09:45] [error] [input:docker:docker.0] error gathering CPU data from /sys/fs/cgroup/cpu/docker/58c33a47212e777cafb7014e44aa6c829b09a62f5f7e3aa316fd5c5144bce2be/cpuacct.usagd
[2022/03/26 09:09:46] [error] [plugins/in_docker/docker.c:315 errno=2] No such file or directory
[2022/03/26 09:09:46] [error] [input:docker:docker.0] error gathering CPU data from /sys/fs/cgroup/cpu/docker/58c33a47212e777cafb7014e44aa6c829b09a62f5f7e3aa316fd5c5144bce2be/cpuacct.usagd
^C[2022/03/26 09:09:46] [engine] caught signal (SIGINT)
[2022/03/26 09:09:46] [ info] [input] pausing docker.0
[2022/03/26 09:09:46] [ warn] [engine] service will shutdown in max 5 seconds
[2022/03/26 09:09:47] [ info] [engine] service has stopped (0 pending tasks)
[2022/03/26 09:09:47] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2022/03/26 09:09:47] [ info] [output:stdout:stdout.0] thread worker #0 stopped
==37262== 
==37262== HEAP SUMMARY:
==37262==     in use at exit: 0 bytes in 0 blocks
==37262==   total heap usage: 1,066 allocs, 1,066 frees, 315,501 bytes allocated
==37262== 
==37262== All heap blocks were freed -- no leaks are possible
==37262== 
==37262== For lists of detected and suppressed errors, rerun with: -s
==37262== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

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.

@@ -791,7 +818,12 @@ static int cb_docker_collect(struct flb_input_instance *ins,
snaps = get_docker_stats(ctx, filtered);
if (!snaps) {
free_docker_list(active);
free_docker_list(filtered);
if (active != filtered) {
/* apply_filters can return the address of acive.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tarruda pushed a commit to tarruda/fluent-bit that referenced this pull request Mar 28, 2022
tarruda pushed a commit to tarruda/fluent-bit that referenced this pull request Apr 1, 2022
tarruda pushed a commit to tarruda/fluent-bit that referenced this pull request Apr 6, 2022
tarruda pushed a commit to tarruda/fluent-bit that referenced this pull request Apr 6, 2022
@edsiper edsiper merged commit db54e69 into fluent:master Apr 26, 2022
@nokute78 nokute78 deleted the mitigate_5149 branch April 26, 2022 12:11
mgeriesa pushed a commit to mgeriesa/fluent-bit that referenced this pull request Oct 25, 2022
demonccc pushed a commit to demonccc/fluent-bit that referenced this pull request Feb 14, 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.

2 participants