- 
  Notifications
 You must be signed in to change notification settings 
- Fork 0
Feature/eager init #74
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
Conversation
Introduces a custom `bin/main.dart` entrypoint to shift the application from a lazy-loading to an eager-loading model. This new entrypoint ensures that all application dependencies are initialized upfront before the Dart Frog server starts. If any initialization step fails, the server process will exit immediately, providing a robust "fail-fast" startup sequence and eliminating race conditions.
Removes all lazy-loading and race-condition handling logic from the `AppDependencies` class. This includes the `_isInitialized` flag, error caching fields, and the `try-catch` block within the `init` method. With the new eager-loading entrypoint, initialization is guaranteed to happen once at startup, making this complex state management logic redundant. The class is now a simpler, more direct dependency initializer.
Updates the root middleware to remove the `AppDependencies.instance.init()` call. Since initialization is now handled eagerly at application startup by the new custom entrypoint, the middleware's responsibility is simplified to only providing the already-initialized dependencies into the request context.
Adds the `executables` section to `pubspec.yaml` to define the new `bin/main.dart` script as a named executable. This allows the server to be started with `dart run :main`, which is the new standard for running the application with the eager-loading strategy.
Updates the README.md to include a new section under "Architecture & Infrastructure" that highlights the "Eager Loading & Fail-Fast Startup" pattern. This change accurately reflects the recent architectural overhaul, explaining the benefits of initializing all dependencies before the server starts, which enhances robustness and stability.
Updates the changelog to include the recent architectural shift to an eager-loading startup model. This is marked as a breaking change (`!`) because it alters the command used to run the server.
Relocates the global logger configuration from the root middleware (`routes/_middleware.dart`) to the new eager-loading entrypoint (`bin/main.dart`). This is an architectural improvement that ensures the logger is configured exactly once when the application process starts, rather than within a middleware that could be re-instantiated. It makes the startup sequence more robust and simplifies the root middleware's responsibilities.
Removes the `await` from the `server.main()` call in the custom entrypoint, as the function returns `void`. Also removes redundant `// ignore: avoid_print` comments that were duplicated by a file-level ignore, resolving linter warnings.
- Integrate shelf_hotreload package for hot reload capability - Wrap server startup logic with withHotreload function - Preserve eager initialization of dependencies - Maintain "fail-fast" approach for production readiness - Update server startup to use createServer function from Dart Frog
...patibility - Update CHANGELOG.md to reflect the new hot reload compatibility of eager loading - Enhance the description to include Dart Frog's hot reload feature
Removes the `reset()` static method and makes the `_instance` field `final` again. This logic was introduced to support hot reloading, which has since been removed from the custom entrypoint. This change cleans up the `AppDependencies` class, removing dead code and preventing confusion about the server's startup behavior.
| Summary of ChangesHello @fulleni, 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 significantly enhances the server's startup reliability and predictability by implementing an eager loading and fail-fast initialization strategy. By ensuring all essential services and connections are fully operational before the server processes any requests, the system gains improved stability and robustness. This change centralizes critical startup logic, preventing the server from ever running in a partially configured or compromised state. Highlights
 Using Gemini Code AssistThe 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  
 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  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
 | 
 
 @gemini-code-assist
 
 gemini-code-assist
 bot
 
 
 left a comment
 
 
 
There was a problem hiding this comment.
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 successfully refactors the application to an eager-loading, fail-fast startup strategy, which is a significant improvement for robustness. The introduction of a custom entrypoint and the simplification of the dependency initialization logic are well-executed. My feedback includes two suggestions for the new bin/main.dart file to further improve its resilience by adding a graceful shutdown mechanism and making the logging more robust.
Implements two key production-readiness features based on code review: 1. **Graceful Shutdown:** The `main.dart` entrypoint now listens for `SIGINT` and `SIGTERM` signals. Upon receiving a signal, it closes the HTTP server to stop accepting new connections, disposes of all application dependencies (like the database connection), and then exits cleanly. This prevents resource leaks. 2. **Atomic Logging:** The logger configuration in `main.dart` has been refactored to use a `StringBuffer` and a single `stdout.write()` call. This ensures that multi-line log entries are written to the console atomically, preventing interleaved output and improving log readability. A defensive check has also been added to `AppDependencies.dispose` to ensure it can be called safely even if initialization failed.
/gemini review
- Add a platform check before listening for SIGTERM signal - Prevent errors on Windows platforms that don't support SIGTERM
 
 @gemini-code-assist
 
 gemini-code-assist
 bot
 
 
 left a comment
 
 
 
There was a problem hiding this comment.
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 significant and valuable architectural change by shifting to an eager, fail-fast server initialization strategy. The new custom entrypoint in bin/main.dart ensures all dependencies are ready before the server starts, improving reliability. The related refactoring in AppDependencies and _middleware.dart correctly simplifies the logic by removing the now-redundant lazy initialization checks. My review includes a couple of suggestions for the new entrypoint to enhance production logging and prevent a race condition that could lead to lost error messages on fatal startup failures.
Fixes a type error where `buildRootHandler()` was being inferred as `dynamic` instead of `Handler`. The fix explicitly casts the result to `Handler` before passing it to the `serve` function, resolving the static analysis error and ensuring type safety.
Replaces the asynchronous `log.severe` call in the main catch block with a direct, synchronous write to `stderr`, followed by `stderr.flush()`. This fixes a race condition where the process could exit before the logger had a chance to write the fatal error message, ensuring that critical startup failure information is never lost.
Uh oh!
There was an error while loading. Please reload this page.
Status
READY
Description
This pull request significantly enhances the server's startup reliability and predictability by implementing an eager loading and fail-fast initialization strategy. By ensuring all essential services and connections are fully operational before the server processes any requests, the system gains improved stability and robustness. This change centralizes critical startup logic, preventing the server from ever running in a partially configured or compromised state.
Type of Change