Skip to content

test_in_monitor_agent: ensure to shutdown plugin instances#5323

Merged
kenhys merged 1 commit into
fluent:masterfrom
Watson1978:test_in_monitor_agent
Apr 20, 2026
Merged

test_in_monitor_agent: ensure to shutdown plugin instances#5323
kenhys merged 1 commit into
fluent:masterfrom
Watson1978:test_in_monitor_agent

Conversation

@Watson1978

@Watson1978 Watson1978 commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Which issue(s) this PR fixes:
Fixes #

What this PR does / why we need it:
Fix thread and resource leaks in test_in_monitor_agent.rb by ensuring proper shutdown sequences for plugin instances.

Currently, the test cases for in_monitor_agent start plugin instances but do not properly shut them down at the end. Because this plugin utilizes helpers (such as http_server and timer), bypassing the proper stop/shutdown lifecycle leaves their background threads running indefinitely.

As a result, executing the test file leaves many orphaned threads, which could lead to test hangs or resource exhaustion in CI environments.

$ ruby -Ilib:test -e "at_exit { puts '--- Thread count at exit: ' + Thread.list.size.to_s;  pp Thread.list }; require './test/plugin/test_in_monitor_agent.rb'"
...
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
24 tests, 42 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5.09 tests/s, 8.90 assertions/s
--- Thread count at exit: 34
[#<Thread:0x00007f35334b7f48 run>,
 #<Thread:0x00007f3516211f90@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351620cd10@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516e1e9c8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516e1a300@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516e74620@flush_thread_0 /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516e730b8@enqueue_thread /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351705df40@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351713fc88@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351409ab78@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3514099160@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35140bdb00@Timeout stdlib thread /home/watson/.rbenv/versions/4.0.2/lib/ruby/4.0.0/timeout.rb:87 sleep_forever>,
 #<Thread:0x00007f3516e18de8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351623b7c8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516076730@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516072b08@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3514059c18@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35140566d0@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35162ce848@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35162c7cc8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35160789b8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35160766b8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35172c1020@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35172e63e8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f792ef40@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f792d230@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35172cc4e8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35172c0350@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f7ad76a8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f7ad53f8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35160808e8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351621c530@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f7902918@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f796e848@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>]

Docs Changes:
N/A

Release Note:
N/A

Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Comment thread test/plugin/test_in_monitor_agent.rb
@Watson1978 Watson1978 added CI Test/CI issues backport to v1.19 We will backport this fix to the LTS branch labels Apr 18, 2026
@Watson1978 Watson1978 added this to the v1.20.0 milestone Apr 18, 2026
@Watson1978 Watson1978 marked this pull request as ready for review April 18, 2026 03:17
@Watson1978 Watson1978 requested a review from kenhys April 18, 2026 03:18

@kenhys kenhys left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@kenhys kenhys merged commit 775970c into fluent:master Apr 20, 2026
21 checks passed
@Watson1978 Watson1978 deleted the test_in_monitor_agent branch April 20, 2026 01:29
github-actions Bot pushed a commit that referenced this pull request Apr 20, 2026
**Which issue(s) this PR fixes**:
Fixes #

**What this PR does / why we need it**:
Fix thread and resource leaks in `test_in_monitor_agent.rb` by ensuring
proper shutdown sequences for plugin instances.

Currently, the test cases for `in_monitor_agent` start plugin instances
but do not properly shut them down at the end. Because this plugin
utilizes helpers (such as `http_server` and `timer`), bypassing the
proper `stop`/`shutdown` lifecycle leaves their background threads
running indefinitely.

As a result, executing the test file leaves many orphaned threads, which
could lead to test hangs or resource exhaustion in CI environments.

```
$ ruby -Ilib:test -e "at_exit { puts '--- Thread count at exit: ' + Thread.list.size.to_s;  pp Thread.list }; require './test/plugin/test_in_monitor_agent.rb'"
...
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
24 tests, 42 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5.09 tests/s, 8.90 assertions/s
--- Thread count at exit: 34
[#<Thread:0x00007f35334b7f48 run>,
 #<Thread:0x00007f3516211f90@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351620cd10@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516e1e9c8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516e1a300@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516e74620@flush_thread_0 /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516e730b8@enqueue_thread /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351705df40@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351713fc88@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351409ab78@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3514099160@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35140bdb00@Timeout stdlib thread /home/watson/.rbenv/versions/4.0.2/lib/ruby/4.0.0/timeout.rb:87 sleep_forever>,
 #<Thread:0x00007f3516e18de8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351623b7c8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516076730@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516072b08@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3514059c18@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35140566d0@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35162ce848@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35162c7cc8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35160789b8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35160766b8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35172c1020@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35172e63e8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f792ef40@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f792d230@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35172cc4e8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35172c0350@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f7ad76a8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f7ad53f8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35160808e8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351621c530@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f7902918@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f796e848@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>]
```

**Docs Changes**:
N/A

**Release Note**:
N/A

Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Watson1978 added a commit that referenced this pull request Apr 20, 2026
…tances (#5323) (#5341)

**Which issue(s) this PR fixes**: 
Backport #5323
Fixes #

**What this PR does / why we need it**: 
Fix thread and resource leaks in `test_in_monitor_agent.rb` by ensuring
proper shutdown sequences for plugin instances.

Currently, the test cases for `in_monitor_agent` start plugin instances
but do not properly shut them down at the end. Because this plugin
utilizes helpers (such as `http_server` and `timer`), bypassing the
proper `stop`/`shutdown` lifecycle leaves their background threads
running indefinitely.

As a result, executing the test file leaves many orphaned threads, which
could lead to test hangs or resource exhaustion in CI environments.

```
$ ruby -Ilib:test -e "at_exit { puts '--- Thread count at exit: ' + Thread.list.size.to_s;  pp Thread.list }; require './test/plugin/test_in_monitor_agent.rb'"
...
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
24 tests, 42 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5.09 tests/s, 8.90 assertions/s
--- Thread count at exit: 34
[#<Thread:0x00007f35334b7f48 run>,
 #<Thread:0x00007f3516211f90@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351620cd10@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516e1e9c8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516e1a300@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516e74620@flush_thread_0 /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516e730b8@enqueue_thread /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351705df40@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351713fc88@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351409ab78@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3514099160@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35140bdb00@Timeout stdlib thread /home/watson/.rbenv/versions/4.0.2/lib/ruby/4.0.0/timeout.rb:87 sleep_forever>,
 #<Thread:0x00007f3516e18de8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351623b7c8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516076730@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3516072b08@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f3514059c18@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35140566d0@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35162ce848@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35162c7cc8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35160789b8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35160766b8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35172c1020@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35172e63e8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f792ef40@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f792d230@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35172cc4e8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35172c0350@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f7ad76a8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f7ad53f8@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f35160808e8@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f351621c530@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f7902918@event_loop /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>,
 #<Thread:0x00007f34f796e848@in_monitor_http_server_helper /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:70 sleep>]
```

**Docs Changes**:
N/A

**Release Note**: 
N/A

Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Shizuo Fujita <fujita@clear-code.com>
@Watson1978 Watson1978 added the backported "backport to LTS" is done label Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport to v1.19 We will backport this fix to the LTS branch backported "backport to LTS" is done CI Test/CI issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants