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

Windows Service: Stopping service sometimes can not be completed forever #3937

Open
daipom opened this issue Oct 31, 2022 · 0 comments
Open
Assignees
Labels
bug Something isn't working windows

Comments

@daipom
Copy link
Contributor

daipom commented Oct 31, 2022

Describe the bug

On Windows, we can run fluentd as a Windows Service.

(Windows PowerShell with Administrative privilege)

# Register
> fluentd.bat --reg-winsvc i
> fluentd.bat --reg-winsvc-fluentdopt '-c C:/test/td-agent.conf -o C:/test/td-agent.log'

# Start the service
> Start-Service fluentdwinsvc

# Stop the service
> Stop-Service fluentdwinsvc

# Unregister
> fluentd.bat --reg-winsvc u

With certain conditions, Stop-Service can not be completed forever.
This happens when multiple supervisor processes are running simultaneously for some reason (perhaps accidentally).

Fluentd uses Event Objects for signals on Windows.

This event's type is Auto-reset event, so the event is automatically unsignalled when one process receives it.

If another supervisor unintentionally receives the event, the process that should be stopped fails to receive it and continues to run.

This makes the service wait for the stopping process forever.

If we kill all fluentd processes (the service process, supervisor, and workers), we can stop the service forcibly.

To Reproduce

  1. Register fluentd as a Windows Service.
> fluentd.bat --reg-winsvc i
> fluentd.bat --reg-winsvc-fluentdopt '-c C:/test/td-agent.conf -o C:/test/td-agent.log'
  1. We can see 3 ruby processes with a single worker setting.
    • Service process, supervisor, and worker
> Start-Service fluentdwinsvc
> ps -ProcessName ruby
Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
226      22    51128      54896       2.09   1792   0 ruby
128      12    15796      16384       0.25   2812   0 ruby
183      17    38084      43380       1.53   3232   0 ruby
  1. We can stop the service while leaving the supervisor and worker alive as following.
# First, make sure the service is stopped.
> Stop-Service fluentdwinsvc

# Then, start the service and immediately stop it.
> Start-Service fluentdwinsvc
> Stop-Service fluentdwinsvc

# We can see 2 ruby processes still alive. (supervisor and worker process)
> ps -ProcessName ruby
Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
  ...                     ...                   ...        ruby
  ...                     ...                   ...        ruby
  1. Start the service again, and now we can see 5 processes.
    • This is the situation where multiple supervisor processes are running simultaneously.
> Start-Service fluentdwinsvc
> ps -ProcessName ruby
Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
  ...                     ...                   ...        ruby
  ...                     ...                   ...        ruby
  ...                     ...                   ...        ruby
  ...                     ...                   ...        ruby
  ...                     ...                   ...        ruby
  1. Then we can reproduce this issue by stopping the service again.

Sorry for the Japanese language environment.

> Stop-Service fluentdwinsvc
警告: サービス 'Fluentd Windows Service (fluentdwinsvc)' の停止を待っています...
警告: サービス 'Fluentd Windows Service (fluentdwinsvc)' の停止を待っています...
警告: サービス 'Fluentd Windows Service (fluentdwinsvc)' の停止を待っています...
(repeats forever)

The messages may be as follows in English

> Stop-Service
WARNING: Waiting for service 'Fluentd Windows Service (fluentdwinsvc)' to stop...
WARNING: Waiting for service 'Fluentd Windows Service (fluentdwinsvc)' to stop...
WARNING: Waiting for service 'Fluentd Windows Service (fluentdwinsvc)' to stop...
(repeats forever)

Expected behavior

The supervisor process of the service stops for sure.

Or, if fluentd doesn't expect multiple supervisors to run simultaneously, all supervisor processes should stop when stopping the service.

Your Environment

- Fluentd version: 1.15.2
- Operating system: Windows 10

Your Configuration

The config has nothing to do with this issue.

<source>
  @type dummy
  tag test.log
  rate 1
  dummy {"message": "This is the test message"}
</source>

<match test.**>
  @type stdout
</match>

Your Error Log

Sorry for the Japanese language environment

> Stop-Service
警告: サービス 'Fluentd Windows Service (fluentdwinsvc)' の停止を待っています...
警告: サービス 'Fluentd Windows Service (fluentdwinsvc)' の停止を待っています...
警告: サービス 'Fluentd Windows Service (fluentdwinsvc)' の停止を待っています...
(repeats forever)

The messages may be as follows in English

> Stop-Service
WARNING: Waiting for service 'Fluentd Windows Service (fluentdwinsvc)' to stop...
WARNING: Waiting for service 'Fluentd Windows Service (fluentdwinsvc)' to stop...
WARNING: Waiting for service 'Fluentd Windows Service (fluentdwinsvc)' to stop...
(repeats forever)

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows
Projects
Status: To-Do
Development

No branches or pull requests

2 participants