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

feat: shutdown in reverse dependency order #147

Merged
merged 1 commit into from
Mar 2, 2024

Conversation

anmonteiro
Copy link
Contributor

processes that depend on others to start may also need to finish before them and perform some cleanup. This change makes sure that's the case.

fixes #145

Copy link
Owner

@F1bonacc1 F1bonacc1 left a comment

Choose a reason for hiding this comment

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

Hey @anmonteiro,

Thanks for the PR, there are definitely scenarios where this feature is required.
I am a bit concerned that for cases where this is not required, this will make the shutdown sequence much longer.

Since it's a behavior change I don't think we can make it the new default.
A global is_ordered_shutdown flag (default false) will do the trick.

Will you be able to add a few ShutDownProject() tests to system_test.go to make sure that it works as expected?

P.S.
Loved the algorithm you used to wait for the dependencies' completion without shutting them down. Nice!

src/app/project_runner.go Outdated Show resolved Hide resolved
src/app/project_runner.go Outdated Show resolved Hide resolved
src/app/project_runner.go Outdated Show resolved Hide resolved
@anmonteiro anmonteiro marked this pull request as ready for review March 2, 2024 20:55
@anmonteiro anmonteiro requested a review from F1bonacc1 March 2, 2024 20:55
@anmonteiro
Copy link
Contributor Author

@F1bonacc1 thanks for the early draft review. I believed I addressed all your review comments in the latest commit.

Just missing the tests, which I'm working on right now.

@anmonteiro
Copy link
Contributor Author

added a skeleton of a test case shutting down the runner and checking for 0 running processes, but I'm not sure how to check that the processes are actually stopped in the order we expect.

isDaemon: true
shutdown:
command: |
echo "C: exiting"
Copy link
Contributor

Choose a reason for hiding this comment

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

You could write these to a file, then assert at the end for the contents to be ordered backwards.

Suggested change
echo "C: exiting"
echo "C: exiting" >> shutdown-inorder.log
sleep 1

Copy link
Owner

Choose a reason for hiding this comment

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

Another approach:
9ac7917

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, thanks. I cherry-picked it to this branch.

@anmonteiro
Copy link
Contributor Author

Not sure why it fails in CI, make test succeeds locally.

return
}
runningProcesses := 0
for _, proc := range runner.runningProcesses {
Copy link
Owner

Choose a reason for hiding this comment

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

Race condition here.
You can replace this block with runner.GetProcessesState() (plural)

Copy link
Owner

Choose a reason for hiding this comment

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

Fixed here:
27c3ab9

@F1bonacc1
Copy link
Owner

F1bonacc1 commented Mar 2, 2024

Not sure why it fails in CI, make test succeeds locally.

Race condition on runner.runningProcesses.
Try make testrace
Left you a comment at the proper line.

@anmonteiro anmonteiro force-pushed the anmonteiro/shutdown-in-order branch from 8941afb to df2fdd4 Compare March 2, 2024 23:19
@anmonteiro
Copy link
Contributor Author

I actually believe it might be the log rendering using ANSI escape codes but not the wanted string slice.

@anmonteiro
Copy link
Contributor Author

pushed a fix using GetProcessesState() and adding NoColor: true to the logger configuration.

@F1bonacc1
Copy link
Owner

Looks good! Thanks!

@F1bonacc1
Copy link
Owner

Will you be able to squash?

address code review

fix: unused variable

refactor: smaller functions

test: shutdown in order

Add shutdown order test

fix: tests
@anmonteiro anmonteiro force-pushed the anmonteiro/shutdown-in-order branch from 4057c9d to dc044a5 Compare March 2, 2024 23:39
Copy link

sonarqubecloud bot commented Mar 2, 2024

Quality Gate Passed Quality Gate passed

Issues
2 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@anmonteiro
Copy link
Contributor Author

Will you be able to squash?

Absolutely. Done.

@F1bonacc1 F1bonacc1 merged commit df422e3 into F1bonacc1:main Mar 2, 2024
3 checks passed
@anmonteiro anmonteiro deleted the anmonteiro/shutdown-in-order branch March 14, 2024 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

process-compose doesn't terminate in dependency order
3 participants