GithubHelp home page GithubHelp logo

Comments (36)

infostreams avatar infostreams commented on May 22, 2024 13

But I'd also like to express my thanks for developing this amazing plugin. My API became 3 times faster on average, without me having to do any changes whatsoever. As far as I'm concerned it's basically magic. Thanks again!

from laravel-swoole.

deepaksp avatar deepaksp commented on May 22, 2024 3

my issue solved after updating config to

/*
|--------------------------------------------------------------------------
| Instances here will be cleared on every request.
|--------------------------------------------------------------------------
*/
'instances' => [
'auth',
],

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024 3

Hi @lbadger ,

Try to add Laravel\Passport\PassportServiceProvider::class to providers in config/swoole_http.php, not sure if it helps thought.

And more details are needed to clarify your issue. You can refer to Issues-Guideline and Debug Guideline and open another issue.

from laravel-swoole.

infostreams avatar infostreams commented on May 22, 2024 1

Hi, since @deepaksp 's setup seems to work now, I will try your suggested setup and report back. Might be tomorrow though.

from laravel-swoole.

infostreams avatar infostreams commented on May 22, 2024 1

Hi @albertcht - I might have a look next week to see if I can make a copy of my (fairly big) app and throw everything out until I have a small reproduction of the problem. Hope it won't take me too long...

from laravel-swoole.

lostncg avatar lostncg commented on May 22, 2024 1

This reproduce steps may as your reference:

websocket.php

Websocket::on('connect', function ($websocket, $request) {
    dump("In connect event: ");
    dump('$request->user() return '.($request->user() ? $request->user()->getName() : 'guest'));
    dump('auth()->user() return '.(auth()->user() ? auth()->user()->getName() : 'guest'));
    dump(auth()->check() ? 'auth()->check() return true' : 'auth()->check() return false');
    dump("----------------------------------------------------------------------------------");
});

Websocket::on('subscribe', function ($websocket, $data) {
    dump("In subscribe event: ");
    dump('auth()->user() return '.(auth()->user() ? auth()->user()->getName() : 'guest'));
    dump(auth()->check() ? 'auth()->check() return true' : 'auth()->check() return false');
    dump("----------------------------------------------------------------------------------");
});

Case 1: without clear auth instance in swoole_http.php

Result as expected when:

  1. user not logged in
  2. logged in

Unexpected result when:

  1. after user logged out

Case 2: with clear auth instance in swoole_http.php

Result as expected when:

  1. user not logged in
  2. logged in

Unexpected result when:

  1. after user logged out

But outcome slightly different with case 1

"----------------------------------------------------------------------------------"
"In connect event: "
"$request->user() return guest"
"auth()->user() return guest"
"auth()->check() return false"
"----------------------------------------------------------------------------------"
"In subscribe event: "
"auth()->user() return user details"
"auth()->check() return true"
"----------------------------------------------------------------------------------"

After set auth instance in config, everything work fine until I try to check user status in custom event "subscribe".

Hope this report can help you in debug.

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024 1

Hi @lostncg ,

Thanks for your report. The behavior in websocket connect might be different from Laravel HTTP. The request passing to connect event callback is processed by my own implementaion. It's implemented with pipeline as well though, but they are separate.

Since getting an auth user depends on request and session by default in Laravel, however, there's no request in these event callbacks. But you inspire me maybe I can design another API for getting an auth user in these event callbacks by sender's socket id.

The websocket will handshke with the server with HTTP protocol first, then upgrade to websocket protocol. That means request will only be available in connect callback.

Anyway, thanks for your report, it helps!

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024 1

Hi everryone,

I decide to close this issue first because:

  1. More and more people commented here to report their issue. However, it will make it difficult to track the original issue.
  2. Some people might think their issues are same or related to this one, but they are caused by different factors (middleware, 3rd packages, etc.).

Thanks a lot for all the comments in this issue, and some debug tips are collected to Debug Guideline.

So please open a new issue that it will be easier for a new discussion.

from laravel-swoole.

emielmolenaar avatar emielmolenaar commented on May 22, 2024 1

Thanks all for trying to debug this issue. I haven't found the culprint yet. I will report back in a new issue if I find something useful.

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024 1

The fastest way I can help you is a laravel repo which can reproduce your bug. Welcome to open another issue if you find something new.

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024

Hi @emielmolenaar ,

There are few things you can do to help you debug:

  1. Make some changes in your config/swoole_http.php
'server' => [
    'options' => [
        'daemonize' => false,
        'worker_num' => 1,
    ]
],
'ob_output' => false,
  1. Add some test routes to your web.php
Route::get('/user', function () {
    return auth()->user();
});
  1. Try to dump some message while resolving auth instance (Illuminate\Auth\AuthServiceProvider::class)
protected function registerAuthenticator()
{
    $this->app->singleton('auth', function ($app) {
        var_dump('auth resoved');
        // the reset code
    }
}
  1. Restart swoole server and try to access http://127.0.0.1:1215/user to check your console if auth resoved is printed.

from laravel-swoole.

emielmolenaar avatar emielmolenaar commented on May 22, 2024

Thanks @albertcht . Just to be sure: sandbox mode is designed to reset auth and auth.driver for each request? Or should I handle that manually?

from laravel-swoole.

emielmolenaar avatar emielmolenaar commented on May 22, 2024

I have been debugging a bit more. Found out that everything is fine when non-authenticated routes are called. If I call a route that is "protected" by Laravel's auth middleware, the user in the last request is available for every request in each browser.

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024

Hi @emielmolenaar ,

Sandbox is a cloned app container. Any instances not in the pre-resolved list will be cleared in a new request.

'view', 'files', 'session', 'session.store', 'routes', 'db', 'db.factory', 'cache', 'cache.store', 'config', 'cookies', 'encrypter', 'hash', 'router', 'translator', 'url', 'log'

So basically you don't need to reset authand auth.driver by yourself.

By the way how did you get your auth user? And will the console show auth resolved if you get your user via auth()->user() in your logic?

from laravel-swoole.

deepaksp avatar deepaksp commented on May 22, 2024

yes i am having same issue

from laravel-swoole.

infostreams avatar infostreams commented on May 22, 2024

Yeah, my routes that use the 'auth' middleware all seem to originate from the same (the previous?) user. Not sure about the specifics though.

from laravel-swoole.

infostreams avatar infostreams commented on May 22, 2024

@deepaksp, thanks for that! Unfortunately it doesn't resolve my issue... 😕

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024

Hi @deepaksp ,

It looks like you didn't enable sandbox. instances config only take effect in non-sandbox mode. Can you please check it again?

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024

Hi guys,

I will check the middleware part again. If you can follow the debug tips above and report your result, that will help me a lot, thanks.

from laravel-swoole.

infostreams avatar infostreams commented on May 22, 2024

Hi @albertcht, if I disable the sandbox mode I can login (somehow), but every API request I do returns with an error 500, saying "Auth guard driver [api] is not defined":

(1/1) InvalidArgumentExceptionAuth guard driver [api] is not defined.
--
in AuthManager.php (line 99)
at AuthManager->resolve('api')in AuthManager.php (line 70)
at AuthManager->guard('api')in Authenticate.php (line 61)
at Authenticate->authenticate(array('api'))in Authenticate.php (line 41)
at Authenticate->handle(object(Request), object(Closure), 'api')in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in ThrottleRequests.php (line 49)
at ThrottleRequests->handle(object(Request), object(Closure), '60', '1')in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in Pipeline.php (line 102)
at Pipeline->then(object(Closure))in Router.php (line 574)
at Router->runRouteWithinStack(object(Route), object(Request))in Router.php (line 533)
at Router->dispatchToRoute(object(Request))in Router.php (line 511)
at Router->dispatch(object(Request))in Kernel.php (line 176)
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))in Pipeline.php (line 30)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in TransformsRequest.php (line 30)
at TransformsRequest->handle(object(Request), object(Closure))in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in TransformsRequest.php (line 30)
at TransformsRequest->handle(object(Request), object(Closure))in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in ValidatePostSize.php (line 27)
at ValidatePostSize->handle(object(Request), object(Closure))in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in CheckForMaintenanceMode.php (line 46)
at CheckForMaintenanceMode->handle(object(Request), object(Closure))in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in Pipeline.php (line 102)
at Pipeline->then(object(Closure))in Kernel.php (line 151)
at Kernel->sendRequestThroughRouter(object(Request))in Kernel.php (line 116)
at Kernel->handle(object(Request))in Application.php (line 296)
at Application->runLaravel(object(Request))in Application.php (line 258)
at Application->run(object(Request))in Manager.php (line 267)

I can login without problems if the sandbox mode is enabled, and the API works correctly, but it doesn't report correctly which user is logged in (it returns the previous one who logged in, I guess – in any case I always seem to end up logged in with the same user account).

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024

Hi @infostreams ,

Basically I am planning to only keep sandbox mode in the near future because the other option is too complicated for most of the users (leading more potential unexpected errors more easily)

I will suggest you keep sandbox mode open.

from laravel-swoole.

infostreams avatar infostreams commented on May 22, 2024

Thanks for the info, I have enabled the sandbox again (because then at least I can test the API, even if the output is not fully correct).

from laravel-swoole.

deepaksp avatar deepaksp commented on May 22, 2024

@albertcht , well sandbox was enable by default as i didnt change anything in setting and as you can see my last post adding auth in instances array fixed the issue for me

from laravel-swoole.

deepaksp avatar deepaksp commented on May 22, 2024

'sandbox_mode' => env('SWOOLE_SANDBOX_MODE', true),
this mean its enable by default right ?

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024

Hi guys,

I just created a new Laravel 5.6 for test purpose here: https://github.com/albertcht/laravel-swoole-demo

In this repo, there are only two routes:

Route::get('/user', function () {
    auth()->loginUsingId(1);
    return auth()->user();
});

Route::get('/auth', function () {
    return auth()->user();
})->middleware('auth');

I set the worker number to one for making things simpler. However, I can't reproduce the same auth user bug, still looking for other clues.

from laravel-swoole.

deepaksp avatar deepaksp commented on May 22, 2024

ok its working fine as expected for me now without any changes ! though wont be able to test much for few days

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024

Hi @deepaksp ,

Yes, your config looks correct. Can you set your partial configs to:

'server' => [
    'options' => [
        'worker_num' => 1,
    ]
],
'ob_output' => false,

And In SwooleTW\Http\Server\Manager, find the method resetOnRequest() and dump a message

if ($this->isSandbox) {
    return;
}
var_dump('called');
// Reset user-customized providers
$this->getApplication()->resetProviders();
// Clear user-customized facades
$this->getApplication()->clearFacades();
// Clear user-customized instances
$this->getApplication()->clearInstances();

The interesting thing is if you enable the sandbox, it won't clear your customized instances.

from laravel-swoole.

elvendor avatar elvendor commented on May 22, 2024

Same here. Tried many variations with no luck.

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024

Only Same here doesn't help. Please refer to the steps above and provide your test data.

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024

Hi all,

FYI, in the newest release v2.3.6, reset mode has been deprecated.

All the requests now will be processed in a container sandbox. instances config was still preserved for cleaning user-customized instances.

Please update to the newest release and republish (php artisan vendor:publish --tag="laravel-swoole" --force) the config files, thanks.

Also report here if your issues are resolved in the new release.

from laravel-swoole.

emielmolenaar avatar emielmolenaar commented on May 22, 2024

Thanks @albertcht . I've checked out your fresh Laravel test repository and the issue does not occur there. I have also checked different session and cache drivers, and all is working fine.

Conclusion: there has to be some library that is fiddling with the user or setting it somewhere in the app container.

I will debug my app further and report back here when I find the culprint.

from laravel-swoole.

infostreams avatar infostreams commented on May 22, 2024

@albertcht There's a typo in your "republish" command, it should be php artisan vendor:publish --tag="swoole-laravel" --force

I've done all the things you suggested. I updated to v2.3.6, updated my config and reduced the number of workers to 1... all to no effect.

@emielmolenaar Here's the dependencies from my composer.json file. Any similarities?

    "require": {
        "php": ">=5.6.4",
        "backpack/base": "^0.7.19",
        "backpack/crud": "^3.2",
        "backpack/permissionmanager": "^2.1",
        "barryvdh/laravel-debugbar": "^2.4",
        "bkwld/croppa": "^4.7",
        "edujugon/push-notification": "^3.0",
        "hashids/hashids": "^2.0",
        "kalnoy/nestedset": "^4.3",
        "kodeine/laravel-acl": "~1.0@dev",
        "laravel/framework": "5.4.*",
        "laravel/passport": "^4.0",
        "laravel/socialite": "^3.0",
        "laravel/tinker": "~1.0",
        "mews/purifier": "^2.0",
        "sabre/uri": "1.2.0",
        "sabre/vobject": "^4.1",
        "sabre/xml": "1.5.0",
        "silber/page-cache": "dev-master",
        "smarcet/caldavclient": "dev-merged",
        "spiritix/lada-cache": "^2.0",
        "swooletw/laravel-swoole": "^2.3"
    },
    "require-dev": {
        "backpack/generators": "^1.1",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7",
        "xethron/migrations-generator": "^2.0",
        "orangehill/iseed": "2.4",
        "filp/whoops": "~1.0"
    },

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024

Hi @infostreams ,

Thanks for your reminding, I've fixed that typo. Setting worker number is to make you debug easier. If you have multiple workers, your requests might be processed by different workers. That possibly makes you have difficulties finding an unexpected result.

Maybe you can try to do a same minimum implementation in a fresh new laravel project without any other redundant packages installed. Let's exclude the possibilities coming from outside first.

from laravel-swoole.

albertcht avatar albertcht commented on May 22, 2024

Hi @emielmolenaar ,

Thanks for your report, not sure if it's affected by other packages, waiting for your good news, thanks!

from laravel-swoole.

lbadger avatar lbadger commented on May 22, 2024

I am also having a similar issue using passport in Lumen running on swoole. Works fine in php7.2-fpm Any Idea's?

[2018-05-25 03:43:27] production.ERROR: InvalidArgumentException: Auth driver [passport] for guard [api] is not defined. in /var/www/api/vendor/illuminate/auth/AuthManager.php:97
Stack trace:
#0 /var/www/api/vendor/illuminate/auth/AuthManager.php(68): Illuminate\Auth\AuthManager->resolve('api')
#1 /var/www/api/app/Http/Middleware/Authenticate.php(38): Illuminate\Auth\AuthManager->guard('api')
#2 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(151): Bitrunr\Http\Middleware\Authenticate->handle(Object(Illuminate\Http\Request), Object(Closure), 'api')
#3 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#4 /var/www/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#5 /var/www/api/vendor/illuminate/routing/Middleware/ThrottleRequests.php(57): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Illuminate\Http\Request))
#6 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(151): Illuminate\Routing\Middleware\ThrottleRequests->handle(Object(Illuminate\Http\Request), Object(Closure), 300, '1')
#7 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#8 /var/www/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#9 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(104): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Illuminate\Http\Request))
#10 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(410): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#11 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(256): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#12 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(160): Laravel\Lumen\Application->handleFoundRoute(Array)
#13 [internal function]: Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(Object(Illuminate\Http\Request))
#14 /var/www/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#15 /var/www/api/vendor/barryvdh/laravel-cors/src/HandlePreflight.php(35): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Illuminate\Http\Request))
#16 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(151): Barryvdh\Cors\HandlePreflight->handle(Object(Illuminate\Http\Request), Object(Closure))
#17 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#18 /var/www/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#19 /var/www/api/vendor/barryvdh/laravel-cors/src/HandleCors.php(36): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Illuminate\Http\Request))
#20 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(151): Barryvdh\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))
#21 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#22 /var/www/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#23 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(104): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Illuminate\Http\Request))
#24 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(410): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#25 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(166): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#26 /var/www/api/vendor/swooletw/laravel-swoole/src/Server/Application.php(209): Laravel\Lumen\Application->dispatch(Object(Illuminate\Http\Request))
#27 /var/www/api/vendor/swooletw/laravel-swoole/src/Server/Application.php(154): SwooleTW\Http\Server\Application->runLumen(Object(Illuminate\Http\Request))
#28 /var/www/api/vendor/swooletw/laravel-swoole/src/Server/Manager.php(257): SwooleTW\Http\Server\Application->run(Object(Illuminate\Http\Request))
#29 [internal function]: SwooleTW\Http\Server\Manager->onRequest(Object(swoole_http_request), Object(swoole_http_response))
#30 /var/www/api/vendor/swooletw/laravel-swoole/src/Server/Manager.php(94): swoole_http_server->start()
#31 /var/www/api/vendor/swooletw/laravel-swoole/src/Commands/HttpServerCommand.php(95): SwooleTW\Http\Server\Manager->run()
#32 /var/www/api/vendor/swooletw/laravel-swoole/src/Commands/HttpServerCommand.php(72): SwooleTW\Http\Commands\HttpServerCommand->start()
#33 /var/www/api/vendor/swooletw/laravel-swoole/src/Commands/HttpServerCommand.php(56): SwooleTW\Http\Commands\HttpServerCommand->runAction()
#34 [internal function]: SwooleTW\Http\Commands\HttpServerCommand->handle()
#35 /var/www/api/vendor/illuminate/container/BoundMethod.php(29): call_user_func_array(Array, Array)
#36 /var/www/api/vendor/illuminate/container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#37 /var/www/api/vendor/illuminate/container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#38 /var/www/api/vendor/illuminate/container/Container.php(564): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#39 /var/www/api/vendor/illuminate/console/Command.php(183): Illuminate\Container\Container->call(Array)
#40 /var/www/api/vendor/symfony/console/Command/Command.php(251): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#41 /var/www/api/vendor/illuminate/console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#42 /var/www/api/vendor/symfony/console/Application.php(865): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#43 /var/www/api/vendor/symfony/console/Application.php(241): Symfony\Component\Console\Application->doRunCommand(Object(SwooleTW\Http\Commands\HttpServerCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#44 /var/www/api/vendor/symfony/console/Application.php(143): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#45 /var/www/api/vendor/illuminate/console/Application.php(89): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#46 /var/www/api/vendor/laravel/lumen-framework/src/Console/Kernel.php(114): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#47 /var/www/api/artisan(35): Laravel\Lumen\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#48 {main} {"exception":"[object] (InvalidArgumentException(code: 0): Auth driver [passport] for guard [api] is not defined. at /var/www/api/vendor/illuminate/auth/AuthManager.php:97)
[stacktrace]
#0 /var/www/api/vendor/illuminate/auth/AuthManager.php(68): Illuminate\\Auth\\AuthManager->resolve('api')
#1 /var/www/api/app/Http/Middleware/Authenticate.php(38): Illuminate\\Auth\\AuthManager->guard('api')
#2 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(151): Bitrunr\\Http\\Middleware\\Authenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure), 'api')
#3 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#4 /var/www/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))
#5 /var/www/api/vendor/illuminate/routing/Middleware/ThrottleRequests.php(57): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#6 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(151): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle(Object(Illuminate\\Http\\Request), Object(Closure), 300, '1')
#7 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#8 /var/www/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))
#9 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(104): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#10 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(410): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#11 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(256): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure))
#12 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(160): Laravel\\Lumen\\Application->handleFoundRoute(Array)
#13 [internal function]: Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}(Object(Illuminate\\Http\\Request))
#14 /var/www/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))
#15 /var/www/api/vendor/barryvdh/laravel-cors/src/HandlePreflight.php(35): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#16 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(151): Barryvdh\\Cors\\HandlePreflight->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#17 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#18 /var/www/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))
#19 /var/www/api/vendor/barryvdh/laravel-cors/src/HandleCors.php(36): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#20 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(151): Barryvdh\\Cors\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#21 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#22 /var/www/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))
#23 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(104): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#24 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(410): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#25 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(166): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure))
#26 /var/www/api/vendor/swooletw/laravel-swoole/src/Server/Application.php(209): Laravel\\Lumen\\Application->dispatch(Object(Illuminate\\Http\\Request))
#27 /var/www/api/vendor/swooletw/laravel-swoole/src/Server/Application.php(154): SwooleTW\\Http\\Server\\Application->runLumen(Object(Illuminate\\Http\\Request))
#28 /var/www/api/vendor/swooletw/laravel-swoole/src/Server/Manager.php(257): SwooleTW\\Http\\Server\\Application->run(Object(Illuminate\\Http\\Request))
#29 [internal function]: SwooleTW\\Http\\Server\\Manager->onRequest(Object(swoole_http_request), Object(swoole_http_response))
#30 /var/www/api/vendor/swooletw/laravel-swoole/src/Server/Manager.php(94): swoole_http_server->start()
#31 /var/www/api/vendor/swooletw/laravel-swoole/src/Commands/HttpServerCommand.php(95): SwooleTW\\Http\\Server\\Manager->run()
#32 /var/www/api/vendor/swooletw/laravel-swoole/src/Commands/HttpServerCommand.php(72): SwooleTW\\Http\\Commands\\HttpServerCommand->start()
#33 /var/www/api/vendor/swooletw/laravel-swoole/src/Commands/HttpServerCommand.php(56): SwooleTW\\Http\\Commands\\HttpServerCommand->runAction()
#34 [internal function]: SwooleTW\\Http\\Commands\\HttpServerCommand->handle()
#35 /var/www/api/vendor/illuminate/container/BoundMethod.php(29): call_user_func_array(Array, Array)
#36 /var/www/api/vendor/illuminate/container/BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#37 /var/www/api/vendor/illuminate/container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Laravel\\Lumen\\Application), Array, Object(Closure))
#38 /var/www/api/vendor/illuminate/container/Container.php(564): Illuminate\\Container\\BoundMethod::call(Object(Laravel\\Lumen\\Application), Array, Array, NULL)
#39 /var/www/api/vendor/illuminate/console/Command.php(183): Illuminate\\Container\\Container->call(Array)
#40 /var/www/api/vendor/symfony/console/Command/Command.php(251): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#41 /var/www/api/vendor/illuminate/console/Command.php(170): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#42 /var/www/api/vendor/symfony/console/Application.php(865): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#43 /var/www/api/vendor/symfony/console/Application.php(241): Symfony\\Component\\Console\\Application->doRunCommand(Object(SwooleTW\\Http\\Commands\\HttpServerCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#44 /var/www/api/vendor/symfony/console/Application.php(143): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#45 /var/www/api/vendor/illuminate/console/Application.php(89): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#46 /var/www/api/vendor/laravel/lumen-framework/src/Console/Kernel.php(114): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#47 /var/www/api/artisan(35): Laravel\\Lumen\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#48 {main}```

Here the require in my composer.json

"require": {
"php": ">=7.2",
"laravel/lumen-framework": "5.6.",
"vlucas/phpdotenv": "~2.2",
"aws/aws-sdk-php": "3.
",
"illuminate/redis": "^5.2",
"firebase/php-jwt": "^4.0",
"lbadger/illuminate-data-migrations": "^2.0.0",
"doctrine/dbal": "^2.5",
"predis/predis": "^1.1",
"barryvdh/laravel-cors": "^0.11.0",
"codeception/codeception": "^2.4",
"codeception/c3": "^2.4",
"dusterio/lumen-passport": "^0.2.6",
"illuminate/routing": "^5.6",
"swooletw/laravel-swoole": "^2.3"
},


I've just modified the swoole_http.php file directly for testing purposes only

'server' => [
    'host' => env('SWOOLE_HTTP_HOST', '127.0.0.1'),
    'port' => env('SWOOLE_HTTP_PORT', '1215'),
    'public_path' => base_path('public'),
    // Determine if to use swoole to respond request for static files
    'handle_static_files' => env('SWOOLE_HANDLE_STATIC', true),
    'options' => [
        'pid_file' => env('SWOOLE_HTTP_PID_FILE', base_path('storage/logs/swoole_http.pid')),
        'log_file' => env('SWOOLE_HTTP_LOG_FILE', base_path('storage/logs/swoole_http.log')),
        'daemonize' => env('SWOOLE_HTTP_DAEMONIZE', false),
        // Normally this value should be 1~4 times larger according to your cpu cores.
        'reactor_num' => env('SWOOLE_HTTP_REACTOR_NUM', 1), //swoole_cpu_num()),
        'worker_num' => env('SWOOLE_HTTP_WORKER_NUM', 1), // swoole_cpu_num()),
        'task_worker_num' => env('SWOOLE_HTTP_TASK_WORKER_NUM', 1), //swoole_cpu_num()),
        // The data to receive can't be larger than buffer_output_size.
        'package_max_length' => 20 * 1024 * 1024,
        // The data to send can't be larger than buffer_output_size.
        'buffer_output_size' => 10 * 1024 * 1024,
        // Max buffer size for socket connections
        'socket_buffer_size' => 128 * 1024 * 1024,
        // Worker will restart after processing this number of request
        'max_request' => 3000,
        // Enable coroutine send
        'send_yield' => true,
        // You must add --enable-openssl while compiling Swoole
        'ssl_cert_file' => null,
        'ssl_key_file' => null
    ],
],

from laravel-swoole.

benyaminl avatar benyaminl commented on May 22, 2024

I just want to add, if we want to use can, gates, and avoid sharing same Auth between different worker, other than adding custom App\Providers\AuthServiceProviders::class on providers in config/swoole_http.php like in #123 (comment), we also need to recall the Illuminate\Auth\AuthServiceProvider::class, in the providers, before the App\Providers\AuthServiceProviders::class, eg

    'providers' => [
        Illuminate\Pagination\PaginationServiceProvider::class,
        Illuminate\Auth\AuthServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
   ],

For some reason, the Illuminate\Auth\Access\Gate, method resolveUser(), won't work and return null, if I don't put the AuthServiceProviders from Laravel Illuminate in the providers in config/swoole_http.php... Its' strange (because based on the concept, it should already init-ed, but seems clearing auth cause this value to be null), but this is a duct tape for my case...

Thanks to @albertcht on the https://github.com/swooletw/laravel-swoole/wiki/Z3.-Debug-Guideline debug guideline, it do help a lot to do debug.

from laravel-swoole.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.