Skip to content

17 feature add graceful shutdown to api and waitgroup - #19

Merged
Aravinda-HWK merged 4 commits into
mainfrom
17-feature-add-graceful-shutdown-to-api-and-waitgroup
Feb 22, 2026
Merged

Aravinda-HWK merged 4 commits into
mainfrom
17-feature-add-graceful-shutdown-to-api-and-waitgroup

Conversation

@maneesha-xyz

Copy link
Copy Markdown
Contributor

Description

Refactor main.go into server.go. Added graceful shutdown.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Code refactoring
  • Other (please describe):

Changes Made

  • Added graceful shutdown to api-server.

Testing

Uncomment the 4 second delay in the health endpoint to test it.

Checklist

  • My code follows the project's coding standards
  • I have tested my changes
  • I have updated the documentation (if needed)
  • My changes don't introduce new warnings or errors

Related Issues

Fixes #17

@maneesha-xyz maneesha-xyz linked an issue Feb 20, 2026 that may be closed by this pull request
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @maneeshaxyz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to the API server by implementing graceful shutdown capabilities. This ensures that the server can shut down cleanly without abruptly terminating active connections, improving the reliability and user experience of the service. Additionally, the server's initialization and startup logic have been refactored into a separate module, leading to a cleaner and more organized codebase.

Highlights

  • Graceful Shutdown: Implemented graceful shutdown for the API server, allowing it to gracefully terminate ongoing requests upon receiving SIGINT or SIGTERM signals.
  • Code Refactoring: Refactored the server startup and configuration logic from main.go into a new dedicated file, server.go, improving modularity and maintainability.
  • Testing Utility: Added a temporary commented-out time.Sleep in the health endpoint to facilitate testing of the new graceful shutdown mechanism.
Changelog
  • api-server/handlers.go
    • Added a commented-out time.Sleep call to the health endpoint for testing graceful shutdown behavior.
  • api-server/main.go
    • Removed the fmt package import.
    • Refactored server initialization and startup logic into a new serve method.
  • api-server/server.go
    • Introduced a new serve method for the application struct.
    • Implemented graceful shutdown functionality using context and os.Signal to handle SIGINT and SIGTERM.
    • Encapsulated HTTP and HTTPS server startup logic, including error handling for http.ErrServerClosed.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@maneesha-xyz

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a graceful shutdown mechanism for the API server and refactors the server startup logic into a separate server.go file. The changes are a good step towards a more robust server. I've found a critical issue in the shutdown logic that could lead to premature termination of the application. I've also identified some areas for improvement regarding error handling and code duplication, and left suggestions to address them. Additionally, there's some leftover test code that should be cleaned up before merging.

Comment thread api-server/server.go Outdated
Comment thread api-server/server.go
Comment thread api-server/handlers.go Outdated

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a graceful shutdown mechanism for the API server and refactors the server startup logic into a new server.go file. The implementation is a good step forward. I've identified a few areas for improvement, including a critical issue with os.Exit being called from a goroutine which could lead to abrupt termination, an incomplete graceful shutdown that doesn't wait for background tasks (where a sync.WaitGroup is a suitable interim solution), some code duplication in the server startup logic, and leftover testing code. Overall, these are valuable changes. Addressing the feedback will make the implementation more robust and maintainable.

Comment thread api-server/server.go
Comment thread api-server/server.go Outdated
Comment thread api-server/handlers.go Outdated
Comment thread api-server/server.go
@maneesha-xyz

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

The PR refactors the server startup logic into a dedicated serve() method and implements graceful shutdown using srv.Shutdown and signal handling. This is a good improvement for reliability. I have one recommendation regarding the use of a buffered channel to prevent a potential goroutine leak during shutdown in error scenarios. Additionally, while the PR title mentions a 'waitgroup', I didn't see any sync.WaitGroup implementation in the current changes; if background tasks are planned, you might want to add this in a future update.

Comment thread api-server/server.go Outdated
@maneesha-xyz
maneesha-xyz marked this pull request as ready for review February 22, 2026 06:29

@Aravinda-HWK Aravinda-HWK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@Aravinda-HWK
Aravinda-HWK merged commit 3f1a9f5 into main Feb 22, 2026
2 checks passed
@Aravinda-HWK
Aravinda-HWK deleted the 17-feature-add-graceful-shutdown-to-api-and-waitgroup branch February 22, 2026 14:20
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.

[FEATURE] Add Graceful Shutdown to API and handle WaitGroup

2 participants