Skip to content

fix(engine): await worker/boss onStart before EngineManager registration - #1760

Merged
jfallows merged 1 commit into
developfrom
claude/fix-pgsql-kafka-npe-wsS5d
May 10, 2026
Merged

jfallows merged 1 commit into
developfrom
claude/fix-pgsql-kafka-npe-wsS5d

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Summary

Fixes an NPE introduced by #1757 that surfaces in binding-pgsql-kafka (ProxyIT.shouldDropTopic and others):

java.lang.NullPointerException: Cannot invoke "EngineRegistry.attach(NamespaceConfig)" because "this.registry" is null
    at EngineWorker.attach(EngineWorker.java:1086)
    at EngineManager.lambda$register$1(EngineManager.java:588)

After #1757, EngineWorker builds its registry (and the per-worker binding/guard/vault/catalog/store/model/metric contexts) inside onStart, on the worker thread, so handler supply(this) calls happen on the owning thread. But EngineWorker.doStart was fire-and-forget — it returned as soon as startOnThread had launched the runner, before the runner had reached onStart.

Engine.start then proceeded to start EngineManager, whose config watch could fire register and call EngineWorker.attach(namespace) → registry.attach(namespace) against a worker whose onStart hadn't yet run, producing the NPE. The pre-#1757 code happened to be safe only because all of that initialization ran in the constructor.

The fix makes startup ordering deterministic with a CountDownLatch per worker / boss:

  • Counted down at the end of onStart in a finally (so init failures still release the latch — await returns and the runner's error handler surfaces the real exception).
  • Awaited at the end of doStart before returning.

EngineBoss currently has no work in onStart, but adding the symmetric scaffolding keeps the worker/boss lifecycle consistent and protects against future asymmetric init.

Test plan

  • ./mvnw -pl runtime/engine clean install — 320 unit + 204 ITs pass; JaCoCo coverage check passes
  • ./mvnw -pl incubator/binding-pgsql-kafka clean verify — ProxyIT 5/5 pass (previously 4 run with 3 errors)
  • ./mvnw -pl runtime/binding-http -am clean verify — green
  • ./mvnw -pl runtime/engine checkstyle:check — clean

https://claude.ai/code/session_01RXTcFJG39snE5KhLkMSALD


Generated by Claude Code

Since #1757 the worker registry is built inside EngineWorker.onStart on the
worker thread, but EngineWorker.doStart returned as soon as the thread was
started. Engine.start then proceeded to start the EngineManager, whose file
watch could fire register before the worker's onStart had run, producing an
NPE on EngineWorker.attach when this.registry was still null.

Add a CountDownLatch in EngineWorker and EngineBoss that is counted down at
the end of onStart (in a finally so init failures still release the latch)
and awaited at the end of doStart, making startup ordering deterministic.

https://claude.ai/code/session_01RXTcFJG39snE5KhLkMSALD

@jfallows jfallows left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM

@jfallows
jfallows merged commit b162be1 into develop May 10, 2026
38 checks passed
@jfallows jfallows self-assigned this May 11, 2026
@jfallows
jfallows deleted the claude/fix-pgsql-kafka-npe-wsS5d branch July 1, 2026 23:07
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.

2 participants