phpro / grumphp

A PHP code-quality tool
MIT License
4.14k stars 430 forks source link

SerializationException when running in parallel #771

Closed R4c00n closed 4 years ago

R4c00n commented 4 years ago
Q A
Version 0.19.0
Bug? yes
New feature? no
Question? no
Documentation? no
Related tickets n/a

When running GrumPHP in parallel mode and without any staged files it get a Uncaught Amp\Serialization\SerializationException in all tasks.

As soon as I stage a file, all tasks are running successfully.

My configuration

# grumphp.yml
grumphp:
    tasks:
        phplint:
            exclude:
                - vendor
            triggered_by: ['php']
        phpcs:
            standard:
                - PSR12
            whitelist_patterns:
                - src
                - test
        phpunit:
            config_file: phpunit.xml
            always_execute: true
        phpstan:
            level: 8

Steps to reproduce:

# Generate empty folder
mkdir tmp
cd tmp
git init
echo "vendor" > .gitignore
pbpaste > grumphp.yml
composer require --dev phpro/grumphp

# Make sure not to stage any files

./vendor/bin/grumphp run

Result:

phplint
=======

Uncaught Amp\Serialization\SerializationException in worker with message "The given data could not be serialized: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::createFrom() must be of the type array, null given, called in /Users/marcelkempf/workspace/vv-fra-heimdall/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php on line 334" and code "0"; use Amp\Parallel\Worker\TaskFailureException::getOriginalTrace() for the stack trace in the worker

phpcs
=====

Uncaught Amp\Serialization\SerializationException in worker with message "The given data could not be serialized: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::createFrom() must be of the type array, null given, called in /Users/marcelkempf/workspace/vv-fra-heimdall/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php on line 334" and code "0"; use Amp\Parallel\Worker\TaskFailureException::getOriginalTrace() for the stack trace in the worker

phpunit
=======

Uncaught Amp\Serialization\SerializationException in worker with message "The given data could not be serialized: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::createFrom() must be of the type array, null given, called in /Users/marcelkempf/workspace/vv-fra-heimdall/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php on line 334" and code "0"; use Amp\Parallel\Worker\TaskFailureException::getOriginalTrace() for the stack trace in the worker

phpstan
=======

Uncaught Amp\Serialization\SerializationException in worker with message "The given data could not be serialized: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::createFrom() must be of the type array, null given, called in /Users/marcelkempf/workspace/vv-fra-heimdall/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php on line 334" and code "0"; use Amp\Parallel\Worker\TaskFailureException::getOriginalTrace() for the stack trace in the worker
To skip commit checks, add -n or --no-verify flag to commit command
veewee commented 4 years ago

Thanks for reporting, can you verify the patch provided in #772 works for you?

R4c00n commented 4 years ago

@veewee It does work :)

yuseferi commented 3 years ago

I have the same problem with the latest version 1.3.0.

>git_branch_name
===============

Uncaught Error in worker with message "Class 'PhpParser\NodeVisitorAbstract' not found" and code "0"; use Amp\Parallel\Worker\TaskFailureError::getOriginalTrace() for the stack trace in the worker

composer
========

Uncaught Error in worker with message "Class 'PhpParser\NodeVisitorAbstract' not found" and code "0"; use Amp\Parallel\Worker\TaskFailureError::getOriginalTrace() for the stack trace in the worker

phpparser
=========

Uncaught Error in worker with message "Class 'PhpParser\NodeVisitorAbstract' not found" and code "0"; use Amp\Parallel\Worker\TaskFailureError::getOriginalTrace() for the stack trace in the worker

phpcs
=====

Uncaught Error in worker with message "Class 'PhpParser\NodeVisitorAbstract' not found" and code "0"; use Amp\Parallel\Worker\TaskFailureError::getOriginalTrace() for the stack trace in the worker
To skip commit checks, add -n or --no-verify flag to commit command

any more idea to resolve the problem?

veewee commented 3 years ago

@yuseferi, This is another issue. Can you open up a new ticket and give some additional information on how to reproduce? Thanks

patpilus commented 3 years ago

I just tried to use Doctrine\DBAL\Connection service as a dependency of my custom grumphp task, but it fails on version 1.3.0 due to serialization issue when running in parallel:

Uncaught Amp\Serialization\SerializationException in worker with message "The given data could not be serialized: Serialization of 'Doctrine\DBAL\Driver\PDOConnection' is not allowed" and code "0"; use Amp\Parallel\Worker\TaskFailureException::getOriginalTrace() for the stack trace in the worker

Full stack trace:

Uncaught Amp\Serialization\SerializationException in worker with message "The given data could not be serialized: Serialization of 'Doctrine\DBAL\Driver\PDOConnection' is not allowed" and code "0"; use Amp\Parallel\Worker\TaskFailureException::getOriginalTrace() for the stack trace in the worker
#0 /app/vendor/amphp/parallel/lib/Worker/Internal/TaskFailure.php(52): Amp\Parallel\Worker\Internal\TaskFailure->createException()
#1 /app/vendor/amphp/parallel/lib/Worker/TaskWorker.php(144): Amp\Parallel\Worker\Internal\TaskFailure->promise()
#2 [internal function]: Amp\Parallel\Worker\TaskWorker->Amp\Parallel\Worker\{closure}()
#3 /app/vendor/amphp/amp/lib/Coroutine.php(118): Generator->send(Object(Amp\Parallel\Worker\Internal\TaskFailure))
#4 /app/vendor/amphp/amp/lib/Internal/Placeholder.php(149): Amp\Coroutine->Amp\{closure}(NULL, Object(Amp\Parallel\Worker\Internal\TaskFailure))
#5 /app/vendor/amphp/amp/lib/Coroutine.php(123): Amp\Coroutine->resolve(Object(Amp\Parallel\Worker\Internal\TaskFailure))
#6 /app/vendor/amphp/amp/lib/Internal/Placeholder.php(149): Amp\Coroutine->Amp\{closure}(NULL, Object(Amp\Parallel\Worker\Internal\TaskFailure))
#7 /app/vendor/amphp/amp/lib/Coroutine.php(123): Amp\Coroutine->resolve(Object(Amp\Parallel\Worker\Internal\TaskFailure))
#8 /app/vendor/amphp/amp/lib/Internal/Placeholder.php(149): Amp\Coroutine->Amp\{closure}(NULL, 'f";s:32:"000000...')
#9 /app/vendor/amphp/amp/lib/Deferred.php(52): class@anonymous->resolve('f";s:32:"000000...')
#10 /app/vendor/amphp/byte-stream/lib/ResourceInputStream.php(109): Amp\Deferred->resolve('f";s:32:"000000...')
#11 /app/vendor/amphp/amp/lib/Loop/Driver.php(119): Amp\ByteStream\ResourceInputStream::Amp\ByteStream\{closure}('r', 'f";s:32:"000000...')
#12 /app/vendor/amphp/amp/lib/Loop/Driver.php(72): Amp\Loop\Driver->tick()
#13 /app/vendor/amphp/amp/lib/Loop.php(95): Amp\Loop\Driver->run()
#14 /app/vendor/amphp/amp/lib/functions.php(229): Amp\Loop::run(Object(Closure))
#15 /app/vendor/phpro/grumphp/src/Runner/Middleware/HandleRunnerMiddleware.php(69): Amp\Promise\wait(Object(Amp\Coroutine))
#16 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\HandleRunnerMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#17 /app/vendor/phpro/grumphp/src/Runner/Middleware/ReportingTasksSectionRunnerMiddleware.php(32): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#18 /app/vendor/phpro/grumphp/src/Runner/Reporting/TaskResultsReporter.php(58): GrumPHP\Runner\Middleware\ReportingTasksSectionRunnerMiddleware->GrumPHP\Runner\Middleware\{closure}()
#19 /app/vendor/phpro/grumphp/src/Runner/Middleware/ReportingTasksSectionRunnerMiddleware.php(33): GrumPHP\Runner\Reporting\TaskResultsReporter->runInSection(Object(Closure))
#20 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\ReportingTasksSectionRunnerMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#21 /app/vendor/phpro/grumphp/src/Runner/Middleware/GroupByPriorityMiddleware.php(41): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#22 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\GroupByPriorityMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#23 /app/vendor/phpro/grumphp/src/Runner/Middleware/EventDispatchingRunnerMiddleware.php(34): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#24 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\EventDispatchingRunnerMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#25 /app/vendor/phpro/grumphp/src/Runner/Middleware/ReportingRunnerMiddleware.php(26): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#26 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\ReportingRunnerMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#27 /app/vendor/phpro/grumphp/src/Runner/Middleware/TasksFilteringRunnerMiddleware.php(20): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#28 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\TasksFilteringRunnerMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#29 /app/vendor/phpro/grumphp/src/Runner/Middleware/FixCodeMiddleware.php(26): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#30 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\FixCodeMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#31 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(38): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#32 /app/vendor/phpro/grumphp/src/Runner/TaskRunner.php(31): GrumPHP\Runner\MiddlewareStack->handle(Object(GrumPHP\Runner\TaskRunnerContext))
#33 /app/vendor/phpro/grumphp/src/Console/Command/RunCommand.php(105): GrumPHP\Runner\TaskRunner->run(Object(GrumPHP\Runner\TaskRunnerContext))
#34 /app/vendor/symfony/console/Command/Command.php(255): GrumPHP\Console\Command\RunCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /app/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /app/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(GrumPHP\Console\Command\RunCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 /app/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 /app/vendor/phpro/grumphp/bin/grumphp(50): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 /app/vendor/phpro/grumphp/bin/grumphp(51): {closure}()
#40 {main}
Amp\Parallel\Worker\TaskFailureException: Uncaught Exception in worker with message "Serialization of 'Doctrine\DBAL\Driver\PDOConnection' is not allowed" and code "0"; use Amp\Parallel\Worker\TaskFailureException::getOriginalTrace() for the stack trace in the worker in /app/vendor/amphp/parallel/lib/Worker/Internal/TaskFailure.php:63
Stack trace:
#0 /app/vendor/amphp/parallel/lib/Worker/Internal/TaskFailure.php(57): Amp\Parallel\Worker\Internal\TaskFailure->createException()
#1 /app/vendor/amphp/parallel/lib/Worker/Internal/TaskFailure.php(52): Amp\Parallel\Worker\Internal\TaskFailure->createException()
#2 /app/vendor/amphp/parallel/lib/Worker/TaskWorker.php(144): Amp\Parallel\Worker\Internal\TaskFailure->promise()
#3 [internal function]: Amp\Parallel\Worker\TaskWorker->Amp\Parallel\Worker\{closure}()
#4 /app/vendor/amphp/amp/lib/Coroutine.php(118): Generator->send(Object(Amp\Parallel\Worker\Internal\TaskFailure))
#5 /app/vendor/amphp/amp/lib/Internal/Placeholder.php(149): Amp\Coroutine->Amp\{closure}(NULL, Object(Amp\Parallel\Worker\Internal\TaskFailure))
#6 /app/vendor/amphp/amp/lib/Coroutine.php(123): Amp\Coroutine->resolve(Object(Amp\Parallel\Worker\Internal\TaskFailure))
#7 /app/vendor/amphp/amp/lib/Internal/Placeholder.php(149): Amp\Coroutine->Amp\{closure}(NULL, Object(Amp\Parallel\Worker\Internal\TaskFailure))
#8 /app/vendor/amphp/amp/lib/Coroutine.php(123): Amp\Coroutine->resolve(Object(Amp\Parallel\Worker\Internal\TaskFailure))
#9 /app/vendor/amphp/amp/lib/Internal/Placeholder.php(149): Amp\Coroutine->Amp\{closure}(NULL, 'f";s:32:"000000...')
#10 /app/vendor/amphp/amp/lib/Deferred.php(52): class@anonymous->resolve('f";s:32:"000000...')
#11 /app/vendor/amphp/byte-stream/lib/ResourceInputStream.php(109): Amp\Deferred->resolve('f";s:32:"000000...')
#12 /app/vendor/amphp/amp/lib/Loop/Driver.php(119): Amp\ByteStream\ResourceInputStream::Amp\ByteStream\{closure}('r', 'f";s:32:"000000...')
#13 /app/vendor/amphp/amp/lib/Loop/Driver.php(72): Amp\Loop\Driver->tick()
#14 /app/vendor/amphp/amp/lib/Loop.php(95): Amp\Loop\Driver->run()
#15 /app/vendor/amphp/amp/lib/functions.php(229): Amp\Loop::run(Object(Closure))
#16 /app/vendor/phpro/grumphp/src/Runner/Middleware/HandleRunnerMiddleware.php(69): Amp\Promise\wait(Object(Amp\Coroutine))
#17 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\HandleRunnerMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#18 /app/vendor/phpro/grumphp/src/Runner/Middleware/ReportingTasksSectionRunnerMiddleware.php(32): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#19 /app/vendor/phpro/grumphp/src/Runner/Reporting/TaskResultsReporter.php(58): GrumPHP\Runner\Middleware\ReportingTasksSectionRunnerMiddleware->GrumPHP\Runner\Middleware\{closure}()
#20 /app/vendor/phpro/grumphp/src/Runner/Middleware/ReportingTasksSectionRunnerMiddleware.php(33): GrumPHP\Runner\Reporting\TaskResultsReporter->runInSection(Object(Closure))
#21 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\ReportingTasksSectionRunnerMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#22 /app/vendor/phpro/grumphp/src/Runner/Middleware/GroupByPriorityMiddleware.php(41): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#23 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\GroupByPriorityMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#24 /app/vendor/phpro/grumphp/src/Runner/Middleware/EventDispatchingRunnerMiddleware.php(34): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#25 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\EventDispatchingRunnerMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#26 /app/vendor/phpro/grumphp/src/Runner/Middleware/ReportingRunnerMiddleware.php(26): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#27 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\ReportingRunnerMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#28 /app/vendor/phpro/grumphp/src/Runner/Middleware/TasksFilteringRunnerMiddleware.php(20): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#29 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\TasksFilteringRunnerMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#30 /app/vendor/phpro/grumphp/src/Runner/Middleware/FixCodeMiddleware.php(26): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#31 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(54): GrumPHP\Runner\Middleware\FixCodeMiddleware->handle(Object(GrumPHP\Runner\TaskRunnerContext), Object(Closure))
#32 /app/vendor/phpro/grumphp/src/Runner/MiddlewareStack.php(38): GrumPHP\Runner\MiddlewareStack::GrumPHP\Runner\{closure}(Object(GrumPHP\Runner\TaskRunnerContext))
#33 /app/vendor/phpro/grumphp/src/Runner/TaskRunner.php(31): GrumPHP\Runner\MiddlewareStack->handle(Object(GrumPHP\Runner\TaskRunnerContext))
#34 /app/vendor/phpro/grumphp/src/Console/Command/RunCommand.php(105): GrumPHP\Runner\TaskRunner->run(Object(GrumPHP\Runner\TaskRunnerContext))
#35 /app/vendor/symfony/console/Command/Command.php(255): GrumPHP\Console\Command\RunCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /app/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 /app/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(GrumPHP\Console\Command\RunCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 /app/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 /app/vendor/phpro/grumphp/bin/grumphp(50): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#40 /app/vendor/phpro/grumphp/bin/grumphp(51): {closure}()
#41 {main}

Can't doctrine DBAL be used in grumphp task?

veewee commented 3 years ago

@patpilus That is a different issue, can you open up a new issue for that?

patpilus commented 3 years ago

Sure!