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

fix: flyteadmin doesn't shutdown servers gracefully #6289

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

lowc1012
Copy link
Contributor

@lowc1012 lowc1012 commented Feb 28, 2025

Tracking issue

#6274

Why are the changes needed?

What changes were proposed in this pull request?

How was this patch tested?

Labels

Please add one or more of the following labels to categorize your PR:

  • added: For new features.
  • changed: For changes in existing functionality.
  • deprecated: For soon-to-be-removed features.
  • removed: For features being removed.
  • fixed: For any bug fixed.
  • security: In case of vulnerabilities

This is important to improve the readability of release notes.

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Summary by Bito

This PR implements graceful shutdown mechanisms for flyteadmin servers by adding signal handling and timeout-based contexts. It enhances error handling in gRPC server startup and ensures both HTTP and gRPC servers shut down properly when receiving termination signals, preventing resource leaks and improving service reliability. A redundant comment was also removed to improve code readability.

Unit tests added: False

Estimated effort to review (1-5, lower is better): 1

@flyte-bot
Copy link
Collaborator

Code Review Agent Run Status

  • Limitations and other issues: ❌ Failure - The AI Code Review Agent skipped reviewing this change because it is configured to exclude certain pull requests based on the source/target branch or the pull request status. You can change the settings here, or contact the agent instance creator at [email protected].

Copy link

codecov bot commented Feb 28, 2025

Codecov Report

Attention: Patch coverage is 0% with 43 lines in your changes missing coverage. Please review.

Project coverage is 58.46%. Comparing base (588ceec) to head (d1714f6).
Report is 22 commits behind head on master.

Files with missing lines Patch % Lines
flyteadmin/pkg/server/service.go 0.00% 43 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6289      +/-   ##
==========================================
+ Coverage   50.37%   58.46%   +8.09%     
==========================================
  Files        1170      937     -233     
  Lines       92851    71121   -21730     
==========================================
- Hits        46774    41582    -5192     
+ Misses      41931    26387   -15544     
+ Partials     4146     3152     -994     
Flag Coverage Δ
unittests-datacatalog 59.06% <ø> (+7.47%) ⬆️
unittests-flyteadmin 56.21% <0.00%> (+4.33%) ⬆️
unittests-flytecopilot 30.99% <ø> (ø)
unittests-flytectl 64.70% <ø> (+2.37%) ⬆️
unittests-flyteidl 76.12% <ø> (?)
unittests-flyteplugins 61.00% <ø> (+6.86%) ⬆️
unittests-flytepropeller 54.79% <ø> (+11.93%) ⬆️
unittests-flytestdlib 64.02% <ø> (+8.68%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lowc1012 lowc1012 changed the title Flyte issue 6274 fix: flyteadmin doesn't shutdown servers gracefully Feb 28, 2025
@eapolinario
Copy link
Contributor

@lowc1012 , is this ready for review?

@lowc1012 lowc1012 marked this pull request as ready for review March 11, 2025 13:13
@flyte-bot
Copy link
Collaborator

flyte-bot commented Mar 11, 2025

Code Review Agent Run #55c786

Actionable Suggestions - 3
  • flyteadmin/pkg/server/service.go - 3
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • flyteadmin/pkg/server/service.go - 2
Review Details
  • Files reviewed - 1 · Commit Range: 490e289..a264c15
    • flyteadmin/pkg/server/service.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

@flyte-bot
Copy link
Collaborator

flyte-bot commented Mar 11, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Bug Fix - Graceful Shutdown Enhancement

service.go - Enhanced shutdown procedures by adding OS signal handling, context timeouts, and running server shutdowns in goroutines to prevent abrupt terminations.

Comment on lines +558 to +563
go func() {
err = srv.Serve(tls.NewListener(conn, srv.TLSConfig))
if err != nil && err != http.ErrServerClosed {
logger.Errorf(ctx, "Failed to start HTTP/2 Server: %v", err)
}
}()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Potential race condition in server startup

The HTTP/2 server is now started in a goroutine, but the function immediately proceeds to wait for shutdown signals. This could lead to a race condition where the shutdown sequence begins before the server is fully initialized. Consider adding a small delay or a readiness check before proceeding to the shutdown logic.

Code suggestion
Check the AI-generated fix before applying
 @@ -558,6 +558,13 @@
  	go func() {
  		err = srv.Serve(tls.NewListener(conn, srv.TLSConfig))
  		if err != nil && err != http.ErrServerClosed {
  			logger.Errorf(ctx, "Failed to start HTTP/2 Server: %v", err)
  		}
  	}()
 +
 +	// Give the server a moment to start before proceeding to shutdown logic
 +	time.Sleep(100 * time.Millisecond)
 +
 +	// Log that the server has started
 +	logger.Infof(ctx, "HTTP/2 Server started successfully on %s", cfg.GetHostAddress())
 

Code Review Run #55c786


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Signed-off-by: Ryan Lo <[email protected]>
@flyte-bot
Copy link
Collaborator

flyte-bot commented Mar 11, 2025

Code Review Agent Run #e9c2cd

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: a264c15..d1714f6
    • flyteadmin/pkg/server/service.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

Refer to the documentation for additional commands.

Configuration

This repository uses code_review_bito You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@lowc1012
Copy link
Contributor Author

@eapolinario please help review it, thank you

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.

3 participants