Skip to content

fix: exclude event dispatcher from worker services reset#310

Closed
kochen wants to merge 1 commit intopatchlevel:3.16.xfrom
kochen:fix/worker-reset-dispatcher-conflict
Closed

fix: exclude event dispatcher from worker services reset#310
kochen wants to merge 1 commit intopatchlevel:3.16.xfrom
kochen:fix/worker-reset-dispatcher-conflict

Conversation

@kochen
Copy link
Copy Markdown
Contributor

@kochen kochen commented Apr 26, 2026

Problem

ResetServicesListener::onWorkerRunningEvent() calls $servicesResetter->reset(), which resets all services tagged with kernel.reset — including debug.event_dispatcher (TraceableEventDispatcher) that is currently dispatching the WorkerRunningEvent.

In symfony/event-dispatcher v8.0.8, TraceableEventDispatcher added dispatchDepth tracking. The reset() call clears $this->dispatchDepth mid-dispatch, causing an "Undefined array key" warning in postProcess():

Warning: Undefined array key "Patchlevel\Worker\Event\WorkerRunningEvent"

Depending on error handling configuration, this warning is promoted to ErrorException, breaking subscription:boot and subscription:run in debug mode.

Fix

Add WorkerResetCompilerPass that, when debug.event_dispatcher is present, builds a worker-specific ServicesResetter excluding the debug event dispatcher. The ResetServicesListener is then rewired to use this filtered resetter.

The global services_resetter remains unchanged — HTTP request resets still include the event dispatcher as before.

Changes

  • src/DependencyInjection/WorkerResetCompilerPass.php — new compiler pass
  • src/PatchlevelEventSourcingBundle.php — register the pass
  • tests/Unit/DependencyInjection/WorkerResetCompilerPassTest.php — unit tests

Fixes #309

@kochen kochen force-pushed the fix/worker-reset-dispatcher-conflict branch 2 times, most recently from 0013176 to e5ad9f2 Compare April 26, 2026 20:46
ResetServicesListener calls ServicesResetter::reset() during
WorkerRunningEvent dispatch. In debug mode, the global services_resetter
includes debug.event_dispatcher (TraceableEventDispatcher), whose reset()
clears dispatchDepth mid-dispatch — causing "Undefined array key" in
postProcess() with symfony/event-dispatcher >= 8.0.8.

Add WorkerResetCompilerPass that builds a worker-specific ServicesResetter
excluding the debug.event_dispatcher, so the global resetter remains
unchanged for HTTP request resets.

Fixes patchlevel#309
@kochen kochen force-pushed the fix/worker-reset-dispatcher-conflict branch from e5ad9f2 to baa36f0 Compare April 26, 2026 21:00
@DanielBadura
Copy link
Copy Markdown
Member

Closing as the issue #309 is resolved and released with https://github.com/patchlevel/event-sourcing-bundle/releases/tag/3.16.1

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.

ResetServicesListener resets TraceableEventDispatcher mid-dispatch, causing "Undefined array key" in Symfony 8.0.8

2 participants