Fluent-bit is frozen, its main thread consumes 100% CPU
Bug report
Priority is low.
Hello @edsiper!
I'm facing another issue with FLB. It has high CPU usage (100% on one core) for a very long time.
The strace shows no activity at all.
The FLB configuration is given below in the sosreport.
The runtime enviroment is the same as i've described in the previous issue #693. So, kubernetes-v1.9.9 at docker-v18.03.
The GDB thread info is given below.
Description
This is so far the only CPU-hungry instance of fluent-bit out of a few hundred. Therefore, I can neither reproduce the issue, nor test if it's present in the master branch. I suppose the issue was triggered by some extremely long log line.
Still i would like to report the issue, because the FLB code of the corresponding infinite loop didn't change from v0.13.2. Maybe you can magically figure out the reason just by looking at the code referenced below?
Profiling
Inside fluent-bit:0.13.2 docker container:
fluent-bit:~$ apt-get -y install gdb procps strace wget unzip
fluent-bit:~$ top -H -p 27251 -n2
PID PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
27251 20 0 1136796 20664 1180 R 99.7 0.2 18655:00 fluent-bit
27253 20 0 1136796 20664 1180 S 0.0 0.2 0:00.00 fluent-bit
fluent-bit:~$ strace -f -p 27251
strace: Process 27251 attached with 2 threads
[pid 27253] epoll_wait(3,
### nothing happens. Pressing Ctrl+c
strace: Process 27253 detached
<detached ...>
### here i'm going to attach to the running FLB a few times and collect backtraces
fluent-bit:~$ wget https://github.com/fluent/fluent-bit/archive/v0.13.2.zip
fluent-bit:~$ unzip v0.13.2.zip -d /tmp
fluent-bit:~$ gdb /fluent-bit/bin/fluent-bit 27251
(gdb) info threads
Id Target Id Frame
* 1 Thread 0x7f8bfc8e1180 (LWP 27251) "fluent-bit" template_execute (ctx=ctx@entry=0x7f8bb731e450, data=data@entry=0x7f8bb72c9200 "\222\327", len=len@entry=17532, off=off@entry=0x7f8bb731e428)
at /tmp/fluent-bit-0.13.2/lib/msgpack-2.1.3/include/msgpack/unpack_template.h:238
2 Thread 0x7f8bf9dff700 (LWP 27253) "fluent-bit" 0x00007f8bfb28e0c3 in epoll_wait () at ../sysdeps/unix/syscall-template.S:84
(gdb) thread 1
[Switching to thread 1 (Thread 0x7f8bfc8e1180 (LWP 27251))]
#0 template_execute (ctx=ctx@entry=0x7f8bb731e450, data=data@entry=0x7f8bb72c9200 "\222\327", len=len@entry=17532, off=off@entry=0x7f8bb731e428)
at /tmp/fluent-bit-0.13.2/lib/msgpack-2.1.3/include/msgpack/unpack_template.h:238
238 ++p;
(gdb) bt
#0 template_execute (ctx=ctx@entry=0x7f8bb731e450, data=data@entry=0x7f8bb72c9200 "\222\327", len=len@entry=17532, off=off@entry=0x7f8bb731e428)
at /tmp/fluent-bit-0.13.2/lib/msgpack-2.1.3/include/msgpack/unpack_template.h:238
#1 0x000055fe983622e5 in msgpack_unpack_next (result=0x7f8bb731ece0, data=0x7f8bb72c9200 "\222\327", len=17532, off=0x7f8bb731ed40) at /tmp/fluent-bit-0.13.2/lib/msgpack-2.1.3/src/unpack.c:651
#2 0x000055fe98132f52 in data_compose (data=0x7f8bb72c9200, bytes=17532, out_buf=0x7f8bb731ed98, out_size=0x7f8bb731ed90, ctx=0x7f8bf9e33600) at /tmp/fluent-bit-0.13.2/plugins/out_forward/forward.c:498
#3 0x000055fe98133107 in cb_forward_flush (data=0x7f8bb72c9200, bytes=17532, tag=0x7f8bf9e8c4f0 "user_k8s", tag_len=8, i_ins=0x7f8bf9e68780, out_context=0x7f8bf9e33600, config=0x7f8bf9e25e40)
at /tmp/fluent-bit-0.13.2/plugins/out_forward/forward.c:565
#4 0x000055fe980f3939 in output_pre_cb_flush () at /tmp/fluent-bit-0.13.2/include/fluent-bit/flb_output.h:311
#5 0x000055fe9837bf87 in co_init () at /tmp/fluent-bit-0.13.2/lib/monkey/deps/flb_libco/amd64.c:117
#6 0x0400040004000400 in ?? ()
#7 0x0000000000000000 in ?? ()
(gdb) detach
Detaching from program: /fluent-bit/bin/fluent-bit, process 27251
### after some time ###
(gdb) attach 27251
Attaching to program: /fluent-bit/bin/fluent-bit, process 27251
(gdb) bt
#0 template_init (ctx=0x7f8bb731e450) at /tmp/fluent-bit-0.13.2/lib/msgpack-2.1.3/include/msgpack/unpack_template.h:64
#1 msgpack_unpack_next (result=0x7f8bb731ece0, data=0x7f8bb72c9200 "\222\327", len=17532, off=0x7f8bb731ed40) at /tmp/fluent-bit-0.13.2/lib/msgpack-2.1.3/src/unpack.c:646
#2 0x000055fe98132f52 in data_compose (data=0x7f8bb72c9200, bytes=17532, out_buf=0x7f8bb731ed98, out_size=0x7f8bb731ed90, ctx=0x7f8bf9e33600) at /tmp/fluent-bit-0.13.2/plugins/out_forward/forward.c:498
#3 0x000055fe98133107 in cb_forward_flush (data=0x7f8bb72c9200, bytes=17532, tag=0x7f8bf9e8c4f0 "user_k8s", tag_len=8, i_ins=0x7f8bf9e68780, out_context=0x7f8bf9e33600, config=0x7f8bf9e25e40)
at /tmp/fluent-bit-0.13.2/plugins/out_forward/forward.c:565
#4 0x000055fe980f3939 in output_pre_cb_flush () at /tmp/fluent-bit-0.13.2/include/fluent-bit/flb_output.h:311
#5 0x000055fe9837bf87 in co_init () at /tmp/fluent-bit-0.13.2/lib/monkey/deps/flb_libco/amd64.c:117
#6 0x0400040004000400 in ?? ()
#7 0x0000000000000000 in ?? ()
(gdb) detach
### after some time ###
(gdb) attach 27251
(gdb) bt
#0 msgpack_unpack_next (result=0x7f8bb731ece0, data=0x7f8bb72c9200 "\222\327", len=17532, off=0x7f8bb731ed40) at /tmp/fluent-bit-0.13.2/lib/msgpack-2.1.3/src/unpack.c:654
#1 0x000055fe98132f52 in data_compose (data=0x7f8bb72c9200, bytes=17532, out_buf=0x7f8bb731ed98, out_size=0x7f8bb731ed90, ctx=0x7f8bf9e33600) at /tmp/fluent-bit-0.13.2/plugins/out_forward/forward.c:498
#2 0x000055fe98133107 in cb_forward_flush (data=0x7f8bb72c9200, bytes=17532, tag=0x7f8bf9e8c4f0 "user_k8s", tag_len=8, i_ins=0x7f8bf9e68780, out_context=0x7f8bf9e33600, config=0x7f8bf9e25e40)
at /tmp/fluent-bit-0.13.2/plugins/out_forward/forward.c:565
#3 0x000055fe980f3939 in output_pre_cb_flush () at /tmp/fluent-bit-0.13.2/include/fluent-bit/flb_output.h:311
#4 0x000055fe9837bf87 in co_init () at /tmp/fluent-bit-0.13.2/lib/monkey/deps/flb_libco/amd64.c:117
#5 0x0400040004000400 in ?? ()
#6 0x0000000000000000 in ?? ()
(gdb) detach
### after some time ###
(gdb) attach 27251
(gdb) bt
#0 0x000055fe980943a7 in ifree (tsd=<optimized out>, slow_path=false, tcache=0x7f8bf9e0d000, ptr=0x7f8bf9ecc000) at /tmp/fluent-bit-0.13.2/lib/jemalloc/src/jemalloc.c:1893
#1 free (ptr=0x7f8bf9ecc000) at /tmp/fluent-bit-0.13.2/lib/jemalloc/src/jemalloc.c:2016
#2 0x000055fe983624c0 in destroy_chunk_list (cl=0x7f8bf9e493b8) at /tmp/fluent-bit-0.13.2/lib/msgpack-2.1.3/src/zone.c:40
#3 msgpack_zone_destroy (zone=zone@entry=0x7f8bf9e493b8) at /tmp/fluent-bit-0.13.2/lib/msgpack-2.1.3/src/zone.c:175
#4 0x000055fe9836264e in msgpack_zone_free (zone=0x7f8bf9e493b8) at /tmp/fluent-bit-0.13.2/lib/msgpack-2.1.3/src/zone.c:220
#5 0x000055fe9836233c in msgpack_unpack_next (result=0x7f8bb731ece0, data=0x7f8bb72c9200 "\222\327", len=17532, off=0x7f8bb731ed40) at /tmp/fluent-bit-0.13.2/lib/msgpack-2.1.3/src/unpack.c:653
#6 0x000055fe98132f52 in data_compose (data=0x7f8bb72c9200, bytes=17532, out_buf=0x7f8bb731ed98, out_size=0x7f8bb731ed90, ctx=0x7f8bf9e33600) at /tmp/fluent-bit-0.13.2/plugins/out_forward/forward.c:498
#7 0x000055fe98133107 in cb_forward_flush (data=0x7f8bb72c9200, bytes=17532, tag=0x7f8bf9e8c4f0 "user_k8s", tag_len=8, i_ins=0x7f8bf9e68780, out_context=0x7f8bf9e33600, config=0x7f8bf9e25e40)
at /tmp/fluent-bit-0.13.2/plugins/out_forward/forward.c:565
#8 0x000055fe980f3939 in output_pre_cb_flush () at /tmp/fluent-bit-0.13.2/include/fluent-bit/flb_output.h:311
#9 0x000055fe9837bf87 in co_init () at /tmp/fluent-bit-0.13.2/lib/monkey/deps/flb_libco/amd64.c:117
#10 0x0400040004000400 in ?? ()
#11 0x0000000000000000 in ?? ()
### and so on. It is stuck inside `plugins/out_forward/forward.c:498`
### at various parts of `msgpack` and `jemalloc` down the stack.
###
fluent-bit:~$ (gdb) quit
The stack trace points to the while loop at what became line 627 of forward.c at master branch.
Looks like infinite loop. Could it be some error handling is missing there?
SOSreport and RAM usage
/fluent-bit/bin/fluent-bit -c /fluent-bit/etc/fluent-bit.conf --sosreport
Fluent-Bit v0.13.2
Copyright (C) Treasure Data
[2018/09/04 22:45:41] [ info] [engine] started (pid=28013)
[2018/09/04 22:45:41] [ warn] [filter_kube] merge_json_log is deprecated, enabling 'merge_log' option instead
[2018/09/04 22:45:41] [ info] [filter_kube] https=1 host=kubernetes.default.svc port=443
[2018/09/04 22:45:41] [ info] [filter_kube] local POD info OK
[2018/09/04 22:45:41] [ info] [filter_kube] testing connectivity with API server...
[2018/09/04 22:45:41] [ info] [filter_kube] API server connectivity OK
Fluent Bit Enterprise - SOS Report
==================================
The following report aims to be used by Fluent Bit and Fluentd Enterprise
Customers of Treasure Data. For more details visit:
https://fluentd.treasuredata.com
[Fluent Bit]
Edition Community Edition
Version 0.13.2
Built Flags JSMN_PARENT_LINKS JSMN_STRICT FLB_HAVE_TLS FLB_HAVE_SQLDB FLB_HAVE_BUFFERING FLB_HAVE_METRICS FLB_HAVE_HTTP_SERVER FLB_HAVE_FLUSH_LIBCO FLB_HAVE_SYSTEMD FLB_HAVE_FORK FLB_HAVE_TIMESPEC_GET FLB_HAVE_PROXY_GO FLB_HAVE_JEMALLOC JEMALLOC_MANGLE FLB_HAVE_LIBBACKTRACE FLB_HAVE_REGEX FLB_HAVE_C_TLS FLB_HAVE_ACCEPT4 FLB_HAVE_INOTIFY
[Operating System]
Name Linux
Release 3.10.0-862.9.1.el7.x86_64
Version #1 SMP Mon Jul 16 16:29:36 UTC 2018
[Hardware]
Architecture x86_64
Processors 2
[Built Plugins]
Inputs cpu mem kmsg tail proc disk systemd netif dummy head exec health serial stdin tcp mqtt lib forward random syslog
Filters grep stdout throttle kubernetes parser record_modifier nest modify
Outputs azure counter es exit file forward http influxdb kafka kafka-rest nats null plot splunk stdout td lib flowcounter
[SERVER] Runtime configuration
Flush 1
Daemon Off
Log_Level Info
[INPUT] Instance
Name systemd.0 (systemd, id=0)
Flags DYN_TAG
Threaded No
Tag sys_systemd
Mem_Buf_Limit 500.0K
Path /var/log/journal
Max_Entries 5000
Read_From_Tail true
[INPUT] Instance
Name systemd.1 (systemd, id=1)
Flags DYN_TAG
Threaded No
Tag sys_k8s
Mem_Buf_Limit 500.0K
Path /var/log/journal
Max_Entries 5000
Systemd_Filter _SYSTEMD_UNIT=docker.service
Read_From_Tail true
[INPUT] Instance
Name systemd.2 (systemd, id=2)
Flags DYN_TAG
Threaded No
Tag user_k8s
Mem_Buf_Limit 500.0K
Path /var/log/journal
Max_Entries 5000
Systemd_Filter _SYSTEMD_UNIT=docker.service
Read_From_Tail true
[FILTER] Instance
Name grep.0 (grep, id=0)
Match *_k8s
Regex CONTAINER_NAME k8s_
Exclude CONTAINER_NAME k8s_fluent-bit
[FILTER] Instance
Name record_modifie (record_modifier, id=0)
Match *_k8s
Remove_key _EXE
Remove_key EXE
Remove_key _CAP_EFFECTIVE
Remove_key CAP_EFFECTIVE
Remove_key _CMDLINE
Remove_key CMDLINE
Remove_key _COMM
Remove_key COMM
Remove_key _GID
Remove_key GID
Remove_key _PID
Remove_key PID
Remove_key _SOURCE_REALTIME_TIMESTAMP
Remove_key SOURCE_REALTIME_TIMESTAMP
Remove_key _SYSTEMD_CGROUP
Remove_key SYSTEMD_CGROUP
Remove_key _SYSTEMD_SLICE
Remove_key SYSTEMD_SLICE
Remove_key _SYSTEMD_UNIT
Remove_key SYSTEMD_UNIT
Remove_key _TRANSPORT
Remove_key TRANSPORT
Remove_key _UID
Remove_key UID
Remove_key PRIORITY
Remove_key SYSLOG_IDENTIFIER
[FILTER] Instance
Name modify.0 (modify, id=0)
Match *
Rename _BOOT_ID BOOT_ID
Rename _CAP_EFFECTIVE CAP_EFFECTIVE
Rename _CMDLINE CMDLINE
Rename _COMM COMM
Rename _EXE EXE
Rename _GID GID
Rename _HOSTNAME HOSTNAME
Rename _MACHINE_ID MACHINE_ID
Rename _PID PID
Rename _SOURCE_REALTIME_TIMESTAMP SOURCE_REALTIME_TIMESTAMP
Rename _SYSTEMD_CGROUP SYSTEMD_CGROUP
Rename _SYSTEMD_SLICE SYSTEMD_SLICE
Rename _SYSTEMD_UNIT SYSTEMD_UNIT
Rename _TRANSPORT TRANSPORT
Rename _UID UID
Rename MESSAGE log
[FILTER] Instance
Name grep.1 (grep, id=1)
Match user_k8s
Exclude CONTAINER_NAME k8s_.*_kube-system_
[FILTER] Instance
Name grep.2 (grep, id=2)
Match sys_k8s
Regex CONTAINER_NAME k8s_.*_kube-system_
Regex CONTAINER_NAME k8s_.*_kube-public_
[FILTER] Instance
Name grep.3 (grep, id=3)
Match sys_systemd
Exclude CONTAINER_NAME k8s_
[FILTER] Instance
Name kubernetes.0 (kubernetes, id=0)
Match *_k8s
Use_Journal true
Tag_Key flb-tag
Kube_URL https://kubernetes.default.svc:443
Kube_CA_File /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
Kube_Token_File /var/run/secrets/kubernetes.io/serviceaccount/token
Merge_JSON_Log On
K8S-Logging.Parser On
K8S-Logging.Exclude On
[OUTPUT] Instance
Name forward.0 (forward, mask_id=1)
Match user_k8s
TLS Active No
Retry Limit 1
Host.TCP_Port 24284
Host.Name user-fluentd.default
[OUTPUT] Instance
Name es.0 (es, mask_id=2)
Match sys_*
TLS Active Yes
TLS.Verify On
TLS.Ca_File /secure/es-tls-ca.crt
TLS.Crt_File (not set)
TLS.Key_File (not set)
TLS.Key_Passwd (not set)
Retry Limit 1
Host.TCP_Port 9200
Host.Name prj-elasticsearch
Logstash_Format On
Time_Key @flb-timestamp
Type flb
Logstash_Prefix k8s
### check if memory usage is not at a limit###
fluent-bit:~$ cat /sys/fs/cgroup/memory/memory.limit_in_bytes
419430400
fluent-bit:~$ cat /sys/fs/cgroup/memory/memory.usage_in_bytes
175599616
fluent-bit:~$ cat /sys/fs/cgroup/memory/memory.stat
cache 140558336
rss 21254144
rss_huge 12582912
mapped_file 2756608
swap 0
pgpgin 45016514
pgpgout 44980586
pgfault 205780312
pgmajfault 388
inactive_anon 0
active_anon 21237760
inactive_file 89280512
active_file 51277824
unevictable 0
hierarchical_memory_limit 419430400
hierarchical_memsw_limit 838860800
total_cache 140558336
total_rss 21254144
total_rss_huge 12582912
total_mapped_file 2756608
total_swap 0
total_pgpgin 45016514
total_pgpgout 44980586
total_pgfault 205780312
total_pgmajfault 388
total_inactive_anon 0
total_active_anon 21237760
total_inactive_file 89280512
total_active_file 51277824
total_unevictable 0
I've reproduced and fixed locally. Will sent an MR during the week. It's indeed return checks missing with regard to msgpack
@kabakaev thanks for report this issue.
Following up with @newtoncorp at #778
Fixed by
- 1bb6080 plugins: validate return value of msgpack_unpack_next()
- b80c5b8 tests: internal: pack: validate return value of msgpack_unpack_next()
- d3fabc5 parser: json: validate return value of msgpack_unpack_next()
- 646f1f5 pack: validate return value of msgpack_unpack_next()
- 3d9eba4 mp: validate return value of msgpack_unpack_next()