Skip to content

Conversation

@ashie
Copy link
Member

@ashie ashie commented Apr 21, 2025

Which issue(s) this PR fixes:
None.

What this PR does / why we need it:
Even if the supervisor process is dead due to config error or etc, the service process will continue running unexpectedly because no one monitor it. This commit fix this issue.

Docs Changes:
Not needed.

Release Note:
Same with the title.

@ashie ashie requested review from Watson1978 and daipom April 21, 2025 07:30
@ashie ashie force-pushed the win32-service-watch-supervisor branch from 7c6e0ab to a254703 Compare April 21, 2025 07:45
@ashie
Copy link
Member Author

ashie commented Apr 21, 2025

Unfortunately it's hard to write tests for windows service.
Instead I tested this code manually and confirmed that it works fine.

Watson1978
Watson1978 previously approved these changes Apr 22, 2025
Copy link
Contributor

@Watson1978 Watson1978 left a comment

Choose a reason for hiding this comment

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

👍🏻

@Watson1978 Watson1978 added the backport to v1.16 We will backport this fix to the LTS branch label Apr 22, 2025
@daipom daipom added this to the v1.19.0 milestone Apr 22, 2025
@ashie ashie marked this pull request as draft April 23, 2025 00:50
@ashie ashie force-pushed the win32-service-watch-supervisor branch from a254703 to 82dba11 Compare April 23, 2025 04:20
@daipom
Copy link
Contributor

daipom commented Apr 23, 2025

Thanks!

I share my check scripts for now.

/test/run.rb

require "win32/daemon"
require "win32/service"

class TestService < Win32::Daemon
  File.open("/test/log/test_service.log", 'a') { |f| f.puts "#{Time.now.inspect}, TestService init" }

  def service_main
    count = 0
    while running?
      File.open("/test/log/test_service.log", 'a') { |f| f.puts "#{Time.now.inspect}, TestService mainloop" }
      sleep 2
      begin
        count += 1
        raise Errno::ECHILD if count >= 2
      rescue Errno::ECHILD
        File.open("/test/log/test_service.log", 'a') { |f| f.puts "#{Time.now.inspect}, TestService trigger stop" }
        SetTheServiceStatus.call(SERVICE_STOPPED, Errno::ECHILD::Errno, 0, 0)
        # Service.stop("testservice")
        # SetEvent(@@hStopEvent)
        break
      end
    end
  end

  def service_stop
    File.open("/test/log/command_receiver_thread.log", 'a') { |f| f.puts "#{Time.now.inspect}, TestService service_stop called" }
  end
end

TestService.new.mainloop
require "win32/service"

# Specify ruby bin path
ruby_path = "C:\\Ruby32-x64\\bin\\ruby.exe"

Win32::Service.create(
  service_name: "testservice",
  binary_path_name: "\"#{ruby_path}\" C:\\test\\run.rb",
  display_name: "testservice",
)
  • Prepare /test/log/ dir
  • Run powershell script
echo "Clear logs"
rm /test/log/*

echo "Start the service"
Start-Service testservice

echo "Waiting for a while ..."
sleep 6

echo "Check service status:"
Get-Service testservice

echo "`nCheck Ruby process:"
ps -Name ruby

echo "`nLog:"
cat /test/log/* | sort

echo "`nLatest System EventLogs:"
Get-EventLog System -newest 3 | fl *

Copy link
Contributor

@daipom daipom left a comment

Choose a reason for hiding this comment

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

@ashie
Thanks!
This seems to be the right way to stop the service process!

I have commented on some minor points.
Please check them.

@ashie ashie force-pushed the win32-service-watch-supervisor branch from 82dba11 to 2ef6a86 Compare April 25, 2025 09:44
Even if the supervisor process is dead due to config error or etc, the
service process will continue running unexpectedly because no one
monitor it. This commit fix this issue.

Signed-off-by: Takuro Ashie <[email protected]>
@ashie ashie force-pushed the win32-service-watch-supervisor branch from 2ef6a86 to 3b9c442 Compare April 25, 2025 09:59
@ashie ashie marked this pull request as ready for review April 25, 2025 10:02
Copy link
Contributor

@daipom daipom left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM!

@daipom daipom merged commit 53bcd3c into master Apr 28, 2025
13 checks passed
@daipom daipom deleted the win32-service-watch-supervisor branch April 28, 2025 01:03
kenhys pushed a commit to kenhys/fluentd that referenced this pull request Apr 30, 2025
**Which issue(s) this PR fixes**:
None.

**What this PR does / why we need it**:
Even if the supervisor process is dead due to config error or etc, the
service process will continue running unexpectedly because no one
monitor it. This commit fix this issue.

**Docs Changes**:
Not needed.

**Release Note**:
Same with the title.

Signed-off-by: Takuro Ashie <[email protected]>
Signed-off-by: Kentaro Hayashi <[email protected]>
kenhys pushed a commit to kenhys/fluentd that referenced this pull request Apr 30, 2025
**Which issue(s) this PR fixes**:
None.

**What this PR does / why we need it**:
Even if the supervisor process is dead due to config error or etc, the
service process will continue running unexpectedly because no one
monitor it. This commit fix this issue.

**Docs Changes**:
Not needed.

**Release Note**:
Same with the title.

Signed-off-by: Takuro Ashie <[email protected]>
Signed-off-by: Kentaro Hayashi <[email protected]>
daipom pushed a commit that referenced this pull request Apr 30, 2025
…#4909) (#4942)

**Which issue(s) this PR fixes**: 
Backport #4909
None.

**What this PR does / why we need it**: 
Even if the supervisor process is dead due to config error or etc, the
service process will continue running unexpectedly because no one
monitor it. This commit fix this issue.

**Docs Changes**:
Not needed.

**Release Note**: 
Same with the title.

Signed-off-by: Takuro Ashie <[email protected]>
Signed-off-by: Kentaro Hayashi <[email protected]>
Co-authored-by: Takuro Ashie <[email protected]>
@daipom daipom added the backported "backport to LTS" is done label Apr 30, 2025
daipom added a commit to daipom/fluentd that referenced this pull request May 13, 2025
After 53bcd3c (fluent#4909), the service
accidentally stops after starting, without stopping the supervisor and
workers.

Signed-off-by: Daijiro Fukuda <[email protected]>
@daipom
Copy link
Contributor

daipom commented May 13, 2025

I'm sorry.
My suggestion was wrong: #4909 (comment)
The if condition was reversed.
The service accidentally stops after starting, without stopping the supervisor and workers.

I have made a PR to fix this bug and adding tests:

daipom added a commit to daipom/fluentd that referenced this pull request May 13, 2025
After 53bcd3c (fluent#4909), the service
accidentally stops after starting, without stopping the supervisor and
workers.

Signed-off-by: Daijiro Fukuda <[email protected]>
daipom added a commit to daipom/fluentd that referenced this pull request May 13, 2025
After 53bcd3c (fluent#4909), the service
accidentally stops after starting, without stopping the supervisor and
workers.

Signed-off-by: Daijiro Fukuda <[email protected]>
daipom added a commit to daipom/fluentd that referenced this pull request May 13, 2025
After 53bcd3c (fluent#4909), the service
accidentally stops after starting, without stopping the supervisor and
workers.

Signed-off-by: Daijiro Fukuda <[email protected]>
daipom added a commit to daipom/fluentd that referenced this pull request May 13, 2025
After 53bcd3c (fluent#4909), the service
accidentally stops after starting, without stopping the supervisor and
workers.

Signed-off-by: Daijiro Fukuda <[email protected]>
daipom added a commit to daipom/fluentd that referenced this pull request May 13, 2025
After 53bcd3c (fluent#4909), the service
accidentally stops after starting, without stopping the supervisor and
workers.

Signed-off-by: Daijiro Fukuda <[email protected]>
daipom added a commit to daipom/fluentd that referenced this pull request May 13, 2025
After 53bcd3c (fluent#4909), the service
accidentally stops after starting, without stopping the supervisor and
workers.

Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Takuro Ashie <[email protected]>
daipom added a commit to daipom/fluentd that referenced this pull request May 14, 2025
After 53bcd3c (fluent#4909), the service
accidentally stops after starting, without stopping the supervisor and
workers.

Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Takuro Ashie <[email protected]>
Co-authored-by: Kentaro Hayashi <[email protected]>
daipom added a commit that referenced this pull request May 14, 2025
**Which issue(s) this PR fixes**: 
This fixes a bug of #4909.

**What this PR does / why we need it**: 
After 53bcd3c (#4909), the service
accidentally stops after starting, without stopping the supervisor and
workers.

**Docs Changes**:
Not needed.

**Release Note**: 
The same as the title.

Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Takuro Ashie <[email protected]>
Co-authored-by: Kentaro Hayashi <[email protected]>
daipom added a commit that referenced this pull request May 14, 2025
**Which issue(s) this PR fixes**:
This fixes a bug of #4909.

**What this PR does / why we need it**:
After 53bcd3c (#4909), the service
accidentally stops after starting, without stopping the supervisor and
workers.

**Docs Changes**:
Not needed.

**Release Note**:
The same as the title.

Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Takuro Ashie <[email protected]>
Co-authored-by: Kentaro Hayashi <[email protected]>
Signed-off-by: Daijiro Fukuda <[email protected]>
daipom added a commit that referenced this pull request May 14, 2025
**Which issue(s) this PR fixes**:
This fixes a bug of #4909.

**What this PR does / why we need it**:
After 53bcd3c (#4909), the service
accidentally stops after starting, without stopping the supervisor and
workers.

**Docs Changes**:
Not needed.

**Release Note**:
The same as the title.

Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Takuro Ashie <[email protected]>
Co-authored-by: Kentaro Hayashi <[email protected]>
Signed-off-by: Daijiro Fukuda <[email protected]>
daipom added a commit that referenced this pull request May 14, 2025
**Which issue(s) this PR fixes**:
This fixes a bug of #4909.

**What this PR does / why we need it**:
After 53bcd3c (#4909), the service
accidentally stops after starting, without stopping the supervisor and
workers.

**Docs Changes**:
Not needed.

**Release Note**:
The same as the title.

Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Takuro Ashie <[email protected]>
Co-authored-by: Kentaro Hayashi <[email protected]>
Signed-off-by: Daijiro Fukuda <[email protected]>
daipom added a commit that referenced this pull request May 14, 2025
…er starting (#4954) (#4955)

**Which issue(s) this PR fixes**:
Backport #4954.

**What this PR does / why we need it**:
After 53bcd3c (#4909), the service
accidentally stops after starting, without stopping the supervisor and
workers.

**Docs Changes**:
Not needed.

**Release Note**:
The same as the title.

Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Takuro Ashie <[email protected]>
Co-authored-by: Kentaro Hayashi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport to v1.16 We will backport this fix to the LTS branch backported "backport to LTS" is done

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants