Skip to content

Make EmulatorLifecycle use more idiomatic Quarkus code#190

Open
geoand wants to merge 1 commit intohectorvent:mainfrom
geoand:lifecycle
Open

Make EmulatorLifecycle use more idiomatic Quarkus code#190
geoand wants to merge 1 commit intohectorvent:mainfrom
geoand:lifecycle

Conversation

@geoand
Copy link
Copy Markdown
Contributor

@geoand geoand commented Apr 3, 2026

No description provided.

Copilot AI review requested due to automatic review settings April 3, 2026 13:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the emulator startup lifecycle to rely on Quarkus’ HTTP server start event rather than manually polling localhost:4566, aiming to run startup hook scripts when the HTTP server is actually ready.

Changes:

  • Removed socket-based port polling and the virtual-thread startup-hook runner.
  • Added an async CDI observer for HttpServerStart to trigger InitializationHook.START execution.
  • Simplified onStart to only log “Ready” immediately when no START hooks exist.

Comment on lines +60 to +62
void onHttpStart(@ObservesAsync HttpServerStart event) {
if ((event.options().getPort() == HTTP_PORT) && initializationHooksRunner.hasHooks(InitializationHook.START)){
try {
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

onHttpStart only runs startup hooks when the HTTP server port equals the hard-coded HTTP_PORT (4566) and there is no fallback/timeout. If the emulator is started on a different port (e.g., via quarkus.http.port override), startup hooks will now be silently skipped and the app will never fail fast, whereas the previous port-polling approach would eventually shut down on timeout. Consider removing the hard-coded port gate (or deriving the expected port from config) and adding a bounded wait/timeout so hook execution can't be skipped indefinitely.

Copilot uses AI. Check for mistakes.
if ((event.options().getPort() == HTTP_PORT) && initializationHooksRunner.hasHooks(InitializationHook.START)){
try {
initializationHooksRunner.run(InitializationHook.START);
LOG.info("=== AWS Local Emulator Ready ===");
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

The catch (Exception e) path will swallow InterruptedException from initializationHooksRunner.run(...) without restoring the thread interrupt status. Handle InterruptedException explicitly (e.g., re-set the interrupt flag) so Quarkus-managed executor threads aren't left in an unexpected state.

Suggested change
LOG.info("=== AWS Local Emulator Ready ===");
LOG.info("=== AWS Local Emulator Ready ===");
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOG.error("Startup hook execution interrupted — shutting down", e);
Quarkus.asyncExit();

Copilot uses AI. Check for mistakes.
Comment on lines +60 to 69
void onHttpStart(@ObservesAsync HttpServerStart event) {
if ((event.options().getPort() == HTTP_PORT) && initializationHooksRunner.hasHooks(InitializationHook.START)){
try {
initializationHooksRunner.run(InitializationHook.START);
LOG.info("=== AWS Local Emulator Ready ===");
} catch (Exception e) {
LOG.error("Startup hook execution failed — shutting down", e);
Quarkus.asyncExit();
}
}
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

New behavior was introduced to run START hooks on HttpServerStart, but there doesn't appear to be coverage ensuring hooks run when the HTTP server starts (and that failures trigger shutdown). Please add/update tests to exercise onHttpStart with a matching server start event and verify initializationHooksRunner.run(START) (and the error path).

Copilot generated this review using guidance from repository custom instructions.
} catch (IOException ignored) {
Thread.sleep(PORT_POLL_INTERVAL_MS);
void onHttpStart(@ObservesAsync HttpServerStart event) {
if ((event.options().getPort() == HTTP_PORT) && initializationHooksRunner.hasHooks(InitializationHook.START)){
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

Minor formatting: add spaces to match the surrounding style (e.g., before { and after ) in the if condition) to keep the codebase consistent and readable.

Suggested change
if ((event.options().getPort() == HTTP_PORT) && initializationHooksRunner.hasHooks(InitializationHook.START)){
if ((event.options().getPort() == HTTP_PORT) && initializationHooksRunner.hasHooks(InitializationHook.START)) {

Copilot uses AI. Check for mistakes.
@hectorvent
Copy link
Copy Markdown
Owner

Hi @geoand,

Thanks for taking the time to contribute! We've seen your PR and will take a look soon.

The Floci team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants