Skip to content

fix: resolve plugin initialization race condition (#75)#101

Merged
MarcosBrendonDePaula merged 1 commit intomainfrom
fix/plugin-init-race-condition
Mar 14, 2026
Merged

fix: resolve plugin initialization race condition (#75)#101
MarcosBrendonDePaula merged 1 commit intomainfrom
fix/plugin-init-race-condition

Conversation

@MarcosBrendonDePaula
Copy link
Copy Markdown
Collaborator

Summary

  • Moved initializeAutomaticPlugins() from fire-and-forget in the constructor to await inside start(), ensuring all auto-discovered plugins are fully initialized before the server accepts traffic.
  • Added 10 unit tests covering lifecycle hook ordering, dependency validation, onConfigLoad execution, and error resilience.

Closes #75

What was the problem?

// constructor — fire-and-forget ❌
this.initializeAutomaticPlugins().catch(error => {
  logger.error('Failed to initialize automatic plugins', { error })
})

If listen() was called before plugin discovery finished, auto-discovered plugins would miss setup(), onBeforeServerStart(), onServerStart(), and onAfterServerStart() hooks.

What changed?

  • core/framework/server.ts: Removed fire-and-forget from constructor; added await this.initializeAutomaticPlugins() at the top of start()
  • tests/unit/core/plugin-init-race-condition.test.ts: 10 new tests

Test plan

  • New test file passes (10/10 tests)
  • Full test suite passes (577 passed, 0 failed)
  • Manual: bun run dev starts without regressions

🤖 Generated with Claude Code

Move `initializeAutomaticPlugins()` from fire-and-forget in the
constructor to `await` inside `start()`, guaranteeing all auto-discovered
plugins are fully loaded before the server accepts traffic.

Add 10 unit tests covering lifecycle hook ordering, dependency
validation after discovery, onConfigLoad execution, and error resilience.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@MarcosBrendonDePaula MarcosBrendonDePaula merged commit e088473 into main Mar 14, 2026
11 checks passed
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.

Corrigir race condition na inicializacao de plugins

1 participant