Skip to content

TaskEventDispatchListener DI loop #133

Open
@kirkmadera

Description

@kirkmadera

Bug Report

I am following the recommended way to run a task event listener, using a TaskEventDispatchListener, but have run into a DI loop.

Mezzio\Swoole\Task\TaskEventDispatchListener > Mezzio\Swoole\Event\EventDispatcherInterface > Mezzio\Swoole\Event\SwooleListenerProvider > Mezzio\Swoole\Task\TaskEventDispatchListener.

Q A
Version(s) 4.9.0

Summary

The following config results in memory exhaustion due to a circular dependency in DI.

<?php

return [
    'mezzio-swoole' => [
        'swoole-http-server' => [
            'listeners' => [
                Event\TaskEvent::class => [
                    TaskEventDispatchListener::class,
                ],
            ],
        ],
    ],
];

Current behavior

Memory exhaustion due to circular dependency.

  1. \Mezzio\Swoole\Event\EventDispatcherInterface requested from container
  2. \Mezzio\Swoole\Event\EventDispatcherFactory runs
  3. Gets \Mezzio\Swoole\Event\SwooleListenerProvider from the container
  4. \Mezzio\Swoole\Event\SwooleListenerProviderFactory runs
  5. Gets configured listeners
  6. One of the listeners is \Mezzio\Swoole\Task\TaskEventDispatchListener
  7. \Mezzio\Swoole\Task\TaskEventDispatchListenerFactory runs
  8. Gets Mezzio\Swoole\Event\EventDispatcherInterface from container

How to reproduce

Add this configuration, then attempt to get \Mezzio\Swoole\Event\EventDispatcherInterface from the container.

<?php

return [
    'mezzio-swoole' => [
        'swoole-http-server' => [
            'listeners' => [
                Event\TaskEvent::class => [
                    TaskEventDispatchListener::class,
                ],
            ],
        ],
    ],
];
<?php

/** @var Laminas\ServiceManager\ServiceManager $container */
$eventDispatcher = $container->get(\Mezzio\Swoole\Event\EventDispatcherInterface::class);

#### Expected behavior

$eventDispatcher returned

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions