test_in_monitor_agent: ensure to shutdown plugin instances#5323
Merged
Conversation
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Watson1978
commented
Apr 18, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.rbby ensuring proper shutdown sequences for plugin instances.Currently, the test cases for
in_monitor_agentstart plugin instances but do not properly shut them down at the end. Because this plugin utilizes helpers (such ashttp_serverandtimer), bypassing the properstop/shutdownlifecycle 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.
Docs Changes:
N/A
Release Note:
N/A