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

msi: guard duplicated instance #622

Closed
wants to merge 2 commits into from
Closed

Conversation

kenhys
Copy link
Contributor

@kenhys kenhys commented Feb 19, 2024

msi: guard multiple Fluentd instance

Before:

  Even though fluentdwinsvc is running, you can execute duplicated
  Fluentd instance.
  It may cause inconsistency of buffer or pos file.

After:

  Guard multiple Fluentd instance when fluendwinsvc service is
  running by default.

  Note that --force option is specified, you can run additional
  Fluentd instance explicitly. (it is same as previous behavior)

@kenhys
Copy link
Contributor Author

kenhys commented Feb 19, 2024

This is PoC

@kenhys kenhys force-pushed the guard-winsvc branch 5 times, most recently from a8a63a5 to 55c7a03 Compare February 20, 2024 05:26
@kenhys
Copy link
Contributor Author

kenhys commented Feb 20, 2024

Basically it will work, but there is one concern.

If user execute directly c:\opt\fluent\bin\fluentd, it can not be blocked.
Usually fluent package prompt will be used, so it is a rare case.

NOTE: search path is like this:

c:\opt\fluent>where fluentd.bat
c:\opt\fluent\fluentd.bat
c:\opt\fluent\bin\fluentd.bat

@kenhys kenhys added this to the 5.0.3 milestone Feb 20, 2024
@kenhys kenhys added the Windows label Feb 20, 2024
@kenhys kenhys marked this pull request as ready for review February 20, 2024 05:45
@kenhys
Copy link
Contributor Author

kenhys commented Feb 20, 2024

It should use findstr /I

@kenhys kenhys force-pushed the guard-winsvc branch 2 times, most recently from 2813851 to 9a3369d Compare February 20, 2024 07:39
@kenhys
Copy link
Contributor Author

kenhys commented Feb 20, 2024

Verified when fluentdwinsvc is running, it will abort like this:

c:\opt\fluent>fluentd.bat -c c:\opt\fluent\etc\fluent\fluentd.conf
Error: can't start duplicate Fluentd instance with same "c:\opt\fluent\etc\fluent\fluentd.conf"

c:\opt\fluent>fluentd.bat
Error: can't start duplicate Fluentd instance with same c:/opt/fluent/etc/fluent/fluentd.conf

@kenhys
Copy link
Contributor Author

kenhys commented Feb 20, 2024

Hmm, it seems that fluentd.bat exit expectedly, but not capture $LASTEXITCODE correctly.

2024-02-20T08:26:44.9840365Z DEBUG:   55+  >>>> Start-Process "C:\\opt\\fluent\\fluentd.bat" -ArgumentList �[m  �[93m
2024-02-20T08:26:44.9842223Z "-c", "C:\\opt\\fluent\\etc\\fluent\\fluentd.conf" -Wait -NoNewWindow�[11X�[11C�[m
2024-02-20T08:26:44.9843565Z �[80X�[80C
2024-02-20T08:26:45.0579514Z �[?25h�[?25lError: can't start duplicate Fluentd instance with same C:/opt/fluent/etc/fluent��[?25h�[?25l
2024-02-20T08:26:45.0580328Z /fluentd.conf�[67X�[67C
2024-02-20T08:26:45.0580632Z �[?25h�[?25l
2024-02-20T08:26:45.0580880Z �[80X�[80C
2024-02-20T08:26:45.9898406Z �[?25h�[93m�[H1�[25;1H�[?25lDEBUG:   56+  >>>> $exitcode = $LASTEXITCODE�[m 
2024-02-20T08:26:45.9929166Z �[?25h�[?25l�[93m�[H1�[25;1H�[?25h�[?25l�[m
2024-02-20T08:26:45.9929643Z �[93mDEBUG:   57+ if ( >>>> $exitcode -ne 2) {�[m�[39X�[39C
2024-02-20T08:26:45.9952814Z �[?25h�[?25l�[93m
2024-02-20T08:26:45.9953365Z DEBUG:   58+      >>>> Write-Host "Failed to abort when it is conflict with �[m    
2024-02-20T08:26:45.9955671Z �[?25h�[?25l
2024-02-20T08:26:45.9956365Z �[93mrunning fluentdwinsvc"�[58X�[58C
2024-02-20T08:26:45.9986556Z �[?25h�[?25l�[m
2024-02-20T08:26:45.9995251Z Failed to abort when it is conflict with running fluentdwinsvc�[18X�[18C�[25;63H�[?25h�[?25l
2024-02-20T08:26:45.9996149Z �[93mDEBUG:   59+      >>>> [Environment]::Exit(1)�[m�[35X�[35C
2024-02-20T08:26:46.0051281Z �[?25h�[?25l
2024-02-20T08:26:46.0051698Z �[80X�[80C
2024-02-20T08:26:50.0433064Z �[?25h�[93m�[HD�[25;1H
2024-02-20T08:26:50.0555867Z ##[error]Process completed with exit code 1.
2024-02-20T08:26:50.0788284Z Post job cleanup.

@kenhys
Copy link
Contributor Author

kenhys commented Feb 21, 2024

With locally built msi, it work as expected.

PS C:\opt\fluent> .\fluentd.bat
Error: can't start duplicate Fluentd instance with same C:/opt/fluent/etc/fluent/fluentd.conf
PS C:\opt\fluent> $exitcode = $LASTEXITCODE
PS C:\opt\fluent> $exitcode
2
PS C:\opt\fluent>

@kenhys
Copy link
Contributor Author

kenhys commented Feb 21, 2024

It's a problem of test code.
It should use -PassThru and capture with .ExitCode.

@kenhys
Copy link
Contributor Author

kenhys commented Feb 21, 2024

Test code was fixed, waiting CI.

@kenhys
Copy link
Contributor Author

kenhys commented Feb 21, 2024

All checks has passed.

@kenhys kenhys requested a review from daipom February 21, 2024 03:09
@daipom daipom linked an issue Feb 21, 2024 that may be closed by this pull request
@daipom daipom added the enhancement New feature or request label Feb 29, 2024
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 for this fix.

My first impression is that it should be a simpler change as a patch version update.
I have concerns about the following points.

  • Specification change
    • If this is to be included in v5.0.3, the specifications should not be changed as much as possible.
    • This PR disables Fluentd from starting if certain conditions are met. This change looks to me too large for a patch version update.
  • Maintainability
    • I am concerned about the maintainability of parsing arguments on this startup script.

For example, what about the following directions?

  • Add a confirmation step when the state of the service is Running.
    • In addition, add force option so that the service can be launched without confirmation even if the state is Running, as the current specification.

@kenhys
Copy link
Contributor Author

kenhys commented Mar 1, 2024

I've forgot to eliminate --force from command line arguments.
It was fixed now.

@kenhys
Copy link
Contributor Author

kenhys commented Mar 1, 2024

pr622

Comment on lines 24 to 28
if "%%p"=="--force" (
set /a FLUENT_FORCE_RUN=1
) else (
set "FLUENT_ARGS=!FLUENT_ARGS! %%p"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I've forgot to eliminate --force from command line arguments.
It was fixed now.

I see...
I'm sorry for not considering this point.

Is this for the possibility of future option conflicts?
This looks like a very difficult issue to me...
Not passing the option to Fluentd does not solve the conflict completely.
(We can not use the option on the Fluentd side in the future.)

Once an argument is added, it is difficult to change it later, so we should be very careful about it.
We should consider this point carefully after releasing 5.0.3.

Copy link
Contributor Author

@kenhys kenhys Mar 1, 2024

Choose a reason for hiding this comment

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

There is a possibility to conflict with fluentd side. (It is not planned yet)
When adding "dare to execute something" option, longer option name is better in conventionally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

--force-running-fluentd or ...
What is the suitable name? 🤔

@kenhys kenhys force-pushed the guard-winsvc branch 2 times, most recently from d54f6e9 to 7c90cde Compare June 24, 2024 05:30
kenhys added 2 commits June 25, 2024 11:04
Before:

  Even though fluentdwinsvc is running, you can execute duplicated
  Fluentd instance.
  It may cause inconsistency of buffer or pos file.

After:

  Guard multiple Fluentd instance when fluendwinsvc service is
  running by default.

  Note that --force-running-multiple-instance option is specified, you
  can run additional Fluentd instance explicitly. (it is same as
  previous behavior)

Signed-off-by: Kentaro Hayashi <[email protected]>
%FLUENT_PACKAGE_TOPDIR% contains trailing /, so
it is redundant to add /.

Signed-off-by: Kentaro Hayashi <[email protected]>
daipom added a commit to daipom/fluent-package-builder that referenced this pull request Jun 25, 2024
Before:

  We can launch Fluentd by fluentd.bat even though fluentdwinsvc is
  running.
  Launching multiple Fluentd with the same config may cause
  inconsistency of the buffers or the pos files.

After:

  We can't launch Fluentd by fluent.bat with the default config path if
  fluentdwinsvc is running.
  If `--config` (`-c`) or `--dry-run` are specified, we can execute
  fluentd.bat as before.

Inspired by @kenhys's PR fluent#622.

Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Kentaro Hayashi <[email protected]>
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 for this, and I'm sorry for the delay.
I have made another version #648, based on this fix.

This PR adds an option to force execution for compatibility.
On the other hand, #648 checks -c (--config) option existence to decide whether to prevent launching for compatibility.
(There are other conditions, but they are not notable. dry-run should be considered as well in this PR direction.)

I think both of these directions are possible.

This PR is more strictly preventing launching multiple instances.

#648 doesn't need a new option.
However, we can launch Fluentd with -c (--config).
So, a possibility of unintentional duplicate launching remains.
(I believe it is less important to consider such a case, though).

Let's consider how to solve #611 based on the information so far.

daipom added a commit to daipom/fluent-package-builder that referenced this pull request Jun 26, 2024
Before:

  We can launch Fluentd by fluentd.bat even though fluentdwinsvc is
  running.
  Launching multiple Fluentd with the same config may cause
  inconsistency of the buffers or the pos files.

After:

  We can't launch Fluentd by fluent.bat with the default config path if
  fluentdwinsvc is running.
  If `--config` (`-c`) or `--dry-run` are specified, we can execute
  fluentd.bat as before.

Inspired by @kenhys's PR fluent#622.

Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Kentaro Hayashi <[email protected]>
daipom added a commit to daipom/fluent-package-builder that referenced this pull request Jun 26, 2024
Before:

  We can launch Fluentd by fluentd.bat even though fluentdwinsvc is
  running.
  Launching multiple Fluentd with the same config may cause
  inconsistency of the buffers or the pos files.

After:

  We can't launch Fluentd by fluent.bat with the default config path if
  fluentdwinsvc is running.
  If some options are specified, we can execute fluentd.bat as before.

Inspired by @kenhys's PR fluent#622.

Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Kentaro Hayashi <[email protected]>
@kenhys
Copy link
Contributor Author

kenhys commented Jun 27, 2024

#647 and #648 approaches are more better alternatives.

@kenhys kenhys closed this Jun 27, 2024
daipom added a commit to daipom/fluent-package-builder that referenced this pull request Jun 27, 2024
Before:

  We can launch Fluentd by fluentd.bat even though fluentdwinsvc is
  running.
  Launching multiple Fluentd with the same config may cause
  inconsistency of the buffers or the pos files.

After:

  We can't launch Fluentd by fluent.bat with the default config path if
  fluentdwinsvc is running.
  If some options are specified, we can execute fluentd.bat as before.

Inspired by @kenhys's PR fluent#622.

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

daipom commented Jun 27, 2024

Thanks for considering.
If we need a force execution option or a strict check whether the config path is the same in the future, let's revive this!

Note: strict check: https://github.com/fluent/fluent-package-builder/blob/f045a795e8f02c9731262f29a6832d95b40c85a1/fluent-package/msi/assets/fluentd.bat

daipom added a commit to daipom/fluent-package-builder that referenced this pull request Jun 27, 2024
Before:

  We can launch Fluentd by fluentd.bat even though fluentdwinsvc is
  running.
  Launching multiple Fluentd with the same config may cause
  inconsistency of the buffers or the pos files.

After:

  We can't launch Fluentd by fluent.bat with the default config path if
  fluentdwinsvc is running.
  If some options are specified, we can execute fluentd.bat as before.

Inspired by @kenhys's PR fluent#622.

Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Kentaro Hayashi <[email protected]>
daipom added a commit to daipom/fluent-package-builder that referenced this pull request Jun 27, 2024
Before:

  We can launch Fluentd by fluentd.bat even though fluentdwinsvc is
  running.
  Launching multiple Fluentd with the same config may cause
  inconsistency of the buffers or the pos files.

After:

  We can't launch Fluentd by fluent.bat with the default config path if
  fluentdwinsvc is running.
  If some options are specified, we can execute fluentd.bat as before.

Inspired by @kenhys's PR fluent#622.

Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Kentaro Hayashi <[email protected]>
kenhys added a commit that referenced this pull request Jun 27, 2024
Before:

  We can launch Fluentd by fluentd.bat even though fluentdwinsvc is
  running.
  Launching multiple Fluentd with the same config may cause
  inconsistency of the buffers or the pos files.

After:

  We can't launch Fluentd by fluent.bat with the default config path if
  fluentdwinsvc is running.
  If some options are specified, we can execute fluentd.bat as before.

Inspired by @kenhys's PR #622.

Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Kentaro Hayashi <[email protected]>
@kenhys kenhys deleted the guard-winsvc branch July 23, 2024 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent accidental duplicate launching
2 participants