dusterio / laravel-aws-worker

Run Laravel (or Lumen) tasks and queue listeners inside of AWS Elastic Beanstalk workers
MIT License
310 stars 59 forks source link

Maximum function nesting level reached on Lumen 5.4.5 #14

Closed EdwinDayot closed 5 years ago

EdwinDayot commented 7 years ago

Hi,

After an update of my composer dependencies (Lumen 5.4.5 and others), it appears that laravel-aws-worker library does not work anymore.

Homestead result

I tried to simulate (including headers and body as expected) the behavior of the SQS and the response leads into the Maximum function nesting level reached:

XDebug disabled

Fatal error: Maximum function nesting level of '512' reached, aborting! in /home/vagrant/my-project/vendor/illuminate/container/Container.php on line 645

Fatal error: Maximum function nesting level of '512' reached, aborting! in /home/vagrant/my-project/vendor/laravel/lumen-framework/src/Concerns/RegistersExceptionHandlers.php on line 53

XDebug enabled

( ! ) Fatal error: Maximum function nesting level of '512' reached, aborting! in /home/vagrant/my-project/vendor/illuminate/container/Container.php on line 645
Call Stack
#   Time    Memory  Function    Location
1   0.0005  361280  {main}( )   .../index.php:0
2   0.1322  1138112 Laravel\Lumen\Application->run( )   .../index.php:28
3   0.1322  1138112 Laravel\Lumen\Application->dispatch( )  .../RoutesRequests.php:475
4   0.1326  1155256 Laravel\Lumen\Application->sendThroughPipeline( )   .../RoutesRequests.php:534
5   0.1367  1157752 Illuminate\Pipeline\Pipeline->then( )   .../RoutesRequests.php:778
6   0.1367  1159144 Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}( )  .../Pipeline.php:102
7   0.1367  1160160 call_user_func:{/home/vagrant/my-project/vendor/laravel/lumen-framework/src/Routing/Pipeline.php:32} ( )    .../Pipeline.php:32
8   0.1367  1160160 Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}( )  .../Pipeline.php:32
9   0.1396  1161608 Vluzrmos\LumenCors\CorsMiddleware->handle( )    .../Pipeline.php:148
10  0.1396  1161984 Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}( )  .../CorsMiddleware.php:43
11  0.1396  1161984 call_user_func:{/home/vagrant/my-project/vendor/laravel/lumen-framework/src/Routing/Pipeline.php:52} ( )    .../Pipeline.php:52
12  0.1396  1161984 Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}( )  .../Pipeline.php:52
13  0.1396  1162360 Laravel\Lumen\Application->handleFoundRoute( )  .../RoutesRequests.php:528
14  0.1396  1162360 Laravel\Lumen\Application->callActionOnArrayBasedRoute( )   .../RoutesRequests.php:628
15  0.1396  1162360 Laravel\Lumen\Application->callControllerAction( )  .../RoutesRequests.php:643
16  0.1433  1230752 Laravel\Lumen\Application->callControllerCallable( )    .../RoutesRequests.php:684
17  0.1433  1230752 Illuminate\Container\Container->call( ) .../RoutesRequests.php:741
18  0.1433  1230752 Illuminate\Container\BoundMethod::call( )   .../Container.php:524
19  0.1433  1231448 Illuminate\Container\BoundMethod::callBoundMethod( )    .../BoundMethod.php:30
20  0.1434  1231528 value( )    .../BoundMethod.php:86
21  0.1434  1231528 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}( ) .../helpers.php:912
22  0.1617  1243064 call_user_func_array:{/home/vagrant/my-project/vendor/illuminate/container/BoundMethod.php:28} ( )  .../BoundMethod.php:28
23  0.1617  1243112 Dusterio\AwsWorker\Controllers\WorkerController->queue( )   .../BoundMethod.php:28
24  0.1674  1248472 Dusterio\AwsWorker\Wrappers\Laravel53Worker->process( ) .../WorkerController.php:83
25  0.1682  1249368 Illuminate\Queue\Worker->process( ) .../Laravel53Worker.php:33
26  0.1694  1250040 Dusterio\AwsWorker\Jobs\AwsJob->fire( ) .../Worker.php:291
27  0.1694  1250040 Illuminate\Queue\Jobs\Job->fire( )  .../AwsJob.php:46
28  0.1759  1260488 Illuminate\Queue\CallQueuedHandler->call( ) .../Job.php:69
29  0.1819  1289000 Illuminate\Bus\Dispatcher->dispatchNow( )   .../CallQueuedHandler.php:42
30  0.1819  1289320 Illuminate\Pipeline\Pipeline->then( )   .../Dispatcher.php:98
31  0.1819  1290016 Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}( )  .../Pipeline.php:102
32  0.1819  1290016 Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}( )  .../Pipeline.php:114
33  0.1819  1290392 Illuminate\Container\Container->call( ) .../Dispatcher.php:94
34  0.1819  1290392 Illuminate\Container\BoundMethod::call( )   .../Container.php:524
35  0.1819  1291088 Illuminate\Container\BoundMethod::callBoundMethod( )    .../BoundMethod.php:30
36  0.1819  1291168 value( )    .../BoundMethod.php:86
37  0.1819  1291168 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}( ) .../helpers.php:912
38  0.1819  1291168 Illuminate\Container\BoundMethod::getMethodDependencies( )  .../BoundMethod.php:28
39  0.1819  1291728 Illuminate\Container\BoundMethod::addDependencyForCallParameter( )  .../BoundMethod.php:115
40  0.1829  1292048 Laravel\Lumen\Application->make( )  .../BoundMethod.php:155
41  0.1829  1292744 Illuminate\Container\Container->make( ) .../Application.php:208
42  0.1829  1292744 Illuminate\Container\Container->build( )    .../Container.php:565
43  0.1829  1292744 Laravel\Lumen\Application->Laravel\Lumen\{closure}( )   .../Container.php:678
44  0.1829  1292744 Laravel\Lumen\Application->loadComponent( ) .../Application.php:243
45  0.1834  1294248 Laravel\Lumen\Application->make( )  .../Application.php:555
46  0.1834  1294248 Illuminate\Container\Container->make( ) .../Application.php:208
47  0.1834  1294248 Illuminate\Container\Container->build( )    .../Container.php:565
48  0.1834  1294248 Laravel\Lumen\Application->Laravel\Lumen\{closure}( )   .../Container.php:678
49  0.1834  1294248 Laravel\Lumen\Application->loadComponent( ) .../Application.php:243
50  0.1834  1294248 Laravel\Lumen\Application->make( )  .../Application.php:555
51  0.1834  1294248 Illuminate\Container\Container->make( ) .../Application.php:208
52  0.1834  1294248 Illuminate\Container\Container->build( )    .../Container.php:565
53  0.1834  1294248 Laravel\Lumen\Application->Laravel\Lumen\{closure}( )   .../Container.php:678
54  0.1834  1294248 Laravel\Lumen\Application->loadComponent( ) .../Application.php:243

etc...

As you can see, 23 to 39 methods calls are making an infinite loop of this:

40  0.1829  1292048 Laravel\Lumen\Application->make( )  .../BoundMethod.php:155
41  0.1829  1292744 Illuminate\Container\Container->make( ) .../Application.php:208
42  0.1829  1292744 Illuminate\Container\Container->build( )    .../Container.php:565
43  0.1829  1292744 Laravel\Lumen\Application->Laravel\Lumen\{closure}( )   .../Container.php:678
44  0.1829  1292744 Laravel\Lumen\Application->loadComponent( ) .../Application.php:243

AWS result

Just an empty response with HTTP 500 Status code (with an execution time of 1700ms probably because of the following logs).

var/log/httpd/error_log file:

[Tue Mar 28 12:52:49.151452 2017] [:error] [pid 28426] [client 127.0.0.1:32934] PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in /var/app/current/vendor/illuminate/container/Container.php on line 549
[Tue Mar 28 12:52:49.595791 2017] [:error] [pid 28426] [client 127.0.0.1:32934] PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in /var/app/current/vendor/laravel/lumen-framework/src/Concerns/RegistersExceptionHandlers.php on line 54
[Tue Mar 28 12:53:02.218553 2017] [:error] [pid 28529] [client 127.0.0.1:36204] PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in /var/app/current/vendor/laravel/lumen-framework/src/Application.php on line 162
[Tue Mar 28 12:53:02.219761 2017] [:error] [pid 28529] [client 127.0.0.1:36204] PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0

Since I don't know where the issue is coming from, I can't fix it nor making a pull request. The issue can also come from my side but it seems that the whole error comes from the core of Lumen and this dependency.

This may be the same issue as #13 except that, in my case, the body is properly filled:

{
  "displayName": "App\\Events\\MyEvent",
  "job": "Illuminate\\Queue\\CallQueuedHandler@call",
  "maxTries": null,
  "timeout": null,
  "data": {
    "commandName": "App\\Events\\MyEvent",
    "command": "O:15:\"App\\Events\\MyEvent\":6:{s:21:\"\u0000App\\Events\\MyEvent\u0000user\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":2:{s:5:\"class\";s:8:\"App\\User\";s:2:\"id\";i:2;}s:21:\"\u0000App\\Events\\MyEvent\u0000myModel\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":2:{s:5:\"class\";s:8:\"App\\MyModel\";s:2:\"id\";i:321;}s:6:\"\u0000*\u0000job\";N;s:10:\"connection\";s:8:\"sqs\";s:5:\"queue\";N;s:5:\"delay\";N;}"
  }
}

Thank you in advance for your help !

dusterio commented 7 years ago

Hmm, thanks for the notification, I will check this tomorrow!

dusterio commented 7 years ago

Hmm, I tried this both in Laravel 5.4.16 and Lumen 5.4.5 - it worked fine in both.

Where did you get Lumen 5.4.13? I don't see it in releases on GitHub: https://github.com/laravel/lumen-framework/releases

EdwinDayot commented 7 years ago

My bad, it was 5.4.5, I'll update the issue.

Maybe I'm not doing the right things to make it work:

bootstrap/app.php:

$app->register(Dusterio\AwsWorker\Integrations\LumenServiceProvider::class);

My config/queue.php is properly configured (with env variables) and I use this:

event((new MyEvent($myParams)));

I should probably make some precisions: the MyEvent class implements the ShouldBroadcast interface since I want this event to be broadcast through Pusher. Following the "Event Broadcasting" section of Laravel's documentation, the event should be pushed to (default or selected) queue.

Maybe I'm not using the right library since it was initially developed for Jobs and not Events ?

EdwinDayot commented 7 years ago

Any news about this issue ?

dusterio commented 7 years ago

@EdwinDayot well, I couldn't reproduce this :/ maybe it's related to your app or your specific use? Sounds like a recursive loop somewhere?

hakuno commented 7 years ago

My Lumen (5.4) also has this problem.

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 8031165417414817424 bytes) in C:\Apache24\htdocs\lirico\vendor\laravel\lumen-framework\src\Concerns\RegistersExceptionHandlers.php on line 47