nuwave / lighthouse

A framework for serving GraphQL from Laravel
https://lighthouse-php.com
MIT License
3.33k stars 434 forks source link

An error occurs in the SubscriptionRegistry when sending a subscription event via Subscription::broadcast with Laravel Octane (Swoole) #2520

Closed danbka33 closed 1 week ago

danbka33 commented 4 months ago

Describe the bug

An error occurs in the SubscriptionRegistry when sending a subscription event.

"debugMessage": "Undefined array key \"scheduleUpdated\"",
"file": "/var/www/app/vendor/nuwave/lighthouse/src/Subscriptions/SubscriptionRegistry.php",
"line": 77,

The event is dispatched from model events.


protected static function boot() {
    self::created(fn (PatientAppointment $appointment) => $appointment->subscriptionBroadcast('created'));
    self::updated(fn (PatientAppointment $appointment) => $appointment->subscriptionBroadcast('updated'));
}

/**
     * Broadcast appointment change to subscription.
     * @param string $action
     * @return void
     */
    private function subscriptionBroadcast(string $action): void
    {
        Subscription::broadcast('scheduleUpdated', [
            [
                'appointment' => $this,
                'action' => $action,
            ],
        ]);
    }

Definition of subscription

extend type Subscription {
    scheduleUpdated(
        date: Date
        statuses: [AppointmentStatus!]
    ): [AppointmentChange!]
}

Expected behavior/Solution

Steps to reproduce

  1. Use Laravel Octane (Swoole)
  2. Create any subscription
  3. Fire subscription from Subscription::broadcast
  4. Got error

Sometimes it works, sometimes it doesn't... I was unable to accurately reproduce the problem in 100% of cases.

Output/Logs

Click to expand ``` { "errors": [ { "message": "Internal server error", "locations": [ { "line": 2, "column": 3 } ], "path": [ "patientAppointmentCreate" ], "extensions": { "debugMessage": "Undefined array key \"scheduleUpdated\"", "file": "/var/www/app/vendor/nuwave/lighthouse/src/Subscriptions/SubscriptionRegistry.php", "line": 77, "trace": [ { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php", "line": 255, "call": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions::handleError(2, 'Undefined array key \"scheduleUpdated\"', '/var/www/app/vendor/nuwave/lighthouse/src/Subscriptions/SubscriptionRegistry.php', 77)" }, { "file": "/var/www/app/vendor/nuwave/lighthouse/src/Subscriptions/SubscriptionRegistry.php", "line": 77, "call": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions::Illuminate\\Foundation\\Bootstrap\\{closure}(2, 'Undefined array key \"scheduleUpdated\"', '/var/www/app/vendor/nuwave/lighthouse/src/Subscriptions/SubscriptionRegistry.php', 77)" }, { "file": "/var/www/app/vendor/nuwave/lighthouse/src/Execution/Utils/Subscription.php", "line": 31, "call": "Nuwave\\Lighthouse\\Subscriptions\\SubscriptionRegistry::subscription('scheduleUpdated')" }, { "file": "/var/www/app/app/Models/PatientAppointment.php", "line": 368, "call": "Nuwave\\Lighthouse\\Execution\\Utils\\Subscription::broadcast('scheduleUpdated', array(1))" }, { "file": "/var/www/app/app/Models/PatientAppointment.php", "line": 154, "call": "App\\Models\\PatientAppointment::subscriptionBroadcast('created')" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php", "line": 458, "call": "App\\Models\\PatientAppointment::App\\Models\\{closure}(instance of App\\Models\\PatientAppointment)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php", "line": 286, "call": "Illuminate\\Events\\Dispatcher::Illuminate\\Events\\{closure}('eloquent.created: App\\Models\\PatientAppointment', array(1))" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php", "line": 266, "call": "Illuminate\\Events\\Dispatcher::invokeListeners('eloquent.created: App\\Models\\PatientAppointment', array(1), false)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php", "line": 215, "call": "Illuminate\\Events\\Dispatcher::dispatch('eloquent.created: App\\Models\\PatientAppointment', array(1))" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php", "line": 1319, "call": "Illuminate\\Database\\Eloquent\\Model::fireModelEvent('created', false)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php", "line": 1137, "call": "Illuminate\\Database\\Eloquent\\Model::performInsert(instance of Illuminate\\Database\\Eloquent\\Builder)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php", "line": 1024, "call": "Illuminate\\Database\\Eloquent\\Model::save()" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Support/helpers.php", "line": 307, "call": "Illuminate\\Database\\Eloquent\\Builder::Illuminate\\Database\\Eloquent\\{closure}(instance of App\\Models\\PatientAppointment)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php", "line": 1023, "function": "tap(instance of App\\Models\\PatientAppointment, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php", "line": 23, "call": "Illuminate\\Database\\Eloquent\\Builder::create(array(11))" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php", "line": 2334, "call": "Illuminate\\Database\\Eloquent\\Model::forwardCallTo(instance of Illuminate\\Database\\Eloquent\\Builder, 'create', array(1))" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php", "line": 2346, "call": "Illuminate\\Database\\Eloquent\\Model::__call('create', array(1))" }, { "file": "/var/www/app/app/GraphQL/Mutations/Patient/Appointment/PatientAppointmentCreate.php", "line": 269, "call": "Illuminate\\Database\\Eloquent\\Model::__callStatic('create', array(1))" }, { "file": "/var/www/app/app/GraphQL/Mutations/Patient/Appointment/PatientAppointmentCreate.php", "line": 93, "call": "App\\GraphQL\\Mutations\\Patient\\Appointment\\PatientAppointmentCreate::createAppointment(instance of App\\Models\\Patient, instance of App\\Models\\User, instance of App\\Models\\Specialization, array(0), instance of Illuminate\\Support\\Carbon, instance of Illuminate\\Support\\Carbon, instance of App\\Enums\\Patient\\PurposeEnum, null, null)" }, { "file": "/var/www/app/app/GraphQL/Directives/GuardLockDirective.php", "line": 62, "call": "App\\GraphQL\\Mutations\\Patient\\Appointment\\PatientAppointmentCreate::__invoke(null, array(4), instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext, instance of Nuwave\\Lighthouse\\Execution\\ResolveInfo)" }, { "file": "/var/www/app/vendor/nuwave/lighthouse/src/Schema/Values/FieldValue.php", "line": 185, "call": "App\\GraphQL\\Directives\\GuardLockDirective::App\\GraphQL\\Directives\\{closure}(null, array(4), instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext, instance of Nuwave\\Lighthouse\\Execution\\ResolveInfo)" }, { "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php", "line": 714, "call": "Nuwave\\Lighthouse\\Schema\\Values\\FieldValue::Nuwave\\Lighthouse\\Schema\\Values\\{closure}(null, array(1), instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext, instance of GraphQL\\Type\\Definition\\ResolveInfo)" }, { "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php", "line": 631, "call": "GraphQL\\Executor\\ReferenceExecutor::resolveFieldValueOrError(instance of GraphQL\\Type\\Definition\\FieldDefinition, instance of GraphQL\\Language\\AST\\FieldNode, instance of Closure, null, instance of GraphQL\\Type\\Definition\\ResolveInfo, instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext)" }, { "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php", "line": 541, "call": "GraphQL\\Executor\\ReferenceExecutor::resolveField(GraphQLType: Mutation, null, instance of ArrayObject(1), array(1), instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext)" }, { "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php", "line": 949, "call": "GraphQL\\Executor\\ReferenceExecutor::GraphQL\\Executor\\{closure}(array(0), 'patientAppointmentCreate')" }, { "call": "GraphQL\\Executor\\ReferenceExecutor::GraphQL\\Executor\\{closure}(array(0), 'patientAppointmentCreate')" }, { "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php", "line": 941, "function": "array_reduce(array(1), instance of Closure, array(0))" }, { "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php", "line": 533, "call": "GraphQL\\Executor\\ReferenceExecutor::promiseReduce(array(1), instance of Closure, array(0))" }, { "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php", "line": 297, "call": "GraphQL\\Executor\\ReferenceExecutor::executeFieldsSerially(GraphQLType: Mutation, null, array(0), instance of ArrayObject(1), instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext)" }, { "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php", "line": 237, "call": "GraphQL\\Executor\\ReferenceExecutor::executeOperation(instance of GraphQL\\Language\\AST\\OperationDefinitionNode, null)" }, { "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/Executor.php", "line": 159, "call": "GraphQL\\Executor\\ReferenceExecutor::doExecute()" }, { "file": "/var/www/app/vendor/webonyx/graphql-php/src/GraphQL.php", "line": 162, "call": "GraphQL\\Executor\\Executor::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, instance of GraphQL\\Language\\AST\\DocumentNode, null, instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext, array(1), 'CreatePatientAppointment', null)" }, { "file": "/var/www/app/vendor/webonyx/graphql-php/src/GraphQL.php", "line": 96, "call": "GraphQL\\GraphQL::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, instance of GraphQL\\Language\\AST\\DocumentNode, null, instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext, array(1), 'CreatePatientAppointment', null, array(29))" }, { "file": "/var/www/app/vendor/nuwave/lighthouse/src/GraphQL.php", "line": 114, "call": "GraphQL\\GraphQL::executeQuery(instance of GraphQL\\Type\\Schema, instance of GraphQL\\Language\\AST\\DocumentNode, null, instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext, array(1), 'CreatePatientAppointment', null, array(29))" }, { "file": "/var/www/app/vendor/nuwave/lighthouse/src/GraphQL.php", "line": 86, "call": "Nuwave\\Lighthouse\\GraphQL::executeParsedQuery(instance of GraphQL\\Language\\AST\\DocumentNode, instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext, array(1), null, 'CreatePatientAppointment')" }, { "file": "/var/www/app/vendor/nuwave/lighthouse/src/GraphQL.php", "line": 208, "call": "Nuwave\\Lighthouse\\GraphQL::executeQueryString('mutation CreatePatientAppointment($input: createPatientAppointmentConstructor!) {\n patientAppointmentCreate(input: $input) {\n base {\n id\n __typename\n }\n secondary {\n id\n __typename\n }\n __typename\n }\n}', instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext, array(1), null, 'CreatePatientAppointment')" }, { "file": "/var/www/app/vendor/nuwave/lighthouse/src/GraphQL.php", "line": 173, "call": "Nuwave\\Lighthouse\\GraphQL::executeOperation(instance of GraphQL\\Server\\OperationParams, instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext)" }, { "file": "/var/www/app/vendor/nuwave/lighthouse/src/Support/Utils.php", "line": 107, "call": "Nuwave\\Lighthouse\\GraphQL::Nuwave\\Lighthouse\\{closure}(instance of GraphQL\\Server\\OperationParams)" }, { "file": "/var/www/app/vendor/nuwave/lighthouse/src/GraphQL.php", "line": 169, "call": "Nuwave\\Lighthouse\\Support\\Utils::mapEach(instance of Closure, instance of GraphQL\\Server\\OperationParams)" }, { "file": "/var/www/app/vendor/nuwave/lighthouse/src/Http/GraphQLController.php", "line": 32, "call": "Nuwave\\Lighthouse\\GraphQL::executeOperationOrOperations(instance of GraphQL\\Server\\OperationParams, instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php", "line": 46, "call": "Nuwave\\Lighthouse\\Http\\GraphQLController::__invoke(instance of Illuminate\\Http\\Request, instance of Nuwave\\Lighthouse\\GraphQL, instance of Illuminate\\Events\\Dispatcher, instance of Laragraph\\Utils\\RequestParser, instance of Nuwave\\Lighthouse\\Execution\\SingleResponse, instance of Nuwave\\Lighthouse\\Execution\\ContextFactory)" }, { "file": "/var/www/app/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingControllerDispatcherTracing.php", "line": 21, "call": "Illuminate\\Routing\\ControllerDispatcher::dispatch(instance of Illuminate\\Routing\\Route, instance of Nuwave\\Lighthouse\\Http\\GraphQLController, '__invoke')" }, { "file": "/var/www/app/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingRoutingDispatcher.php", "line": 19, "call": "Sentry\\Laravel\\Tracing\\Routing\\TracingControllerDispatcherTracing::Sentry\\Laravel\\Tracing\\Routing\\{closure}()" }, { "file": "/var/www/app/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingControllerDispatcherTracing.php", "line": 20, "call": "Sentry\\Laravel\\Tracing\\Routing\\TracingRoutingDispatcher::wrapRouteDispatch(instance of Closure, instance of Illuminate\\Routing\\Route)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Route.php", "line": 259, "call": "Sentry\\Laravel\\Tracing\\Routing\\TracingControllerDispatcherTracing::dispatch(instance of Illuminate\\Routing\\Route, instance of Nuwave\\Lighthouse\\Http\\GraphQLController, '__invoke')" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Route.php", "line": 205, "call": "Illuminate\\Routing\\Route::runController()" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 806, "call": "Illuminate\\Routing\\Route::run()" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 144, "call": "Illuminate\\Routing\\Router::Illuminate\\Routing\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/nuwave/lighthouse/src/Http/Middleware/AttemptAuthentication.php", "line": 22, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Nuwave\\Lighthouse\\Http\\Middleware\\AttemptAuthentication::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/nuwave/lighthouse/src/Http/Middleware/AcceptJson.php", "line": 24, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Nuwave\\Lighthouse\\Http\\Middleware\\AcceptJson::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php", "line": 121, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php", "line": 64, "call": "Illuminate\\Session\\Middleware\\StartSession::handleStatefulRequest(instance of Illuminate\\Http\\Request, instance of Illuminate\\Session\\Store, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Illuminate\\Session\\Middleware\\StartSession::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php", "line": 37, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php", "line": 67, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Illuminate\\Cookie\\Middleware\\EncryptCookies::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 119, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 805, "call": "Illuminate\\Pipeline\\Pipeline::then(instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 784, "call": "Illuminate\\Routing\\Router::runRouteWithinStack(instance of Illuminate\\Routing\\Route, instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 748, "call": "Illuminate\\Routing\\Router::runRoute(instance of Illuminate\\Http\\Request, instance of Illuminate\\Routing\\Route)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 737, "call": "Illuminate\\Routing\\Router::dispatchToRoute(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 200, "call": "Illuminate\\Routing\\Router::dispatch(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 144, "call": "Illuminate\\Foundation\\Http\\Kernel::Illuminate\\Foundation\\Http\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestIpMiddleware.php", "line": 45, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Sentry\\Laravel\\Http\\SetRequestIpMiddleware::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestMiddleware.php", "line": 31, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Sentry\\Laravel\\Http\\SetRequestMiddleware::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/app/Http/Middleware/LanguageMiddleware.php", "line": 26, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "App\\Http\\Middleware\\LanguageMiddleware::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php", "line": 21, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php", "line": 31, "call": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php", "line": 21, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php", "line": 40, "call": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Illuminate\\Foundation\\Http\\Middleware\\TrimStrings::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php", "line": 27, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php", "line": 99, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php", "line": 62, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Illuminate\\Http\\Middleware\\HandleCors::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php", "line": 39, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Illuminate\\Http\\Middleware\\TrustProxies::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Middleware.php", "line": 87, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 183, "call": "Sentry\\Laravel\\Tracing\\Middleware::handle(instance of Illuminate\\Http\\Request, instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 119, "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 175, "call": "Illuminate\\Pipeline\\Pipeline::then(instance of Closure)" }, { "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 144, "call": "Illuminate\\Foundation\\Http\\Kernel::sendRequestThroughRouter(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/octane/src/ApplicationGateway.php", "line": 36, "call": "Illuminate\\Foundation\\Http\\Kernel::handle(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/octane/src/Worker.php", "line": 84, "call": "Laravel\\Octane\\ApplicationGateway::handle(instance of Illuminate\\Http\\Request)" }, { "file": "/var/www/app/vendor/laravel/octane/bin/swoole-server", "line": 120, "call": "Laravel\\Octane\\Worker::handle(instance of Illuminate\\Http\\Request, instance of Laravel\\Octane\\RequestContext)" }, { "function": "{closure}(instance of OpenSwoole\\Http\\Request, instance of OpenSwoole\\Http\\Response)" }, { "file": "/var/www/app/vendor/laravel/octane/bin/swoole-server", "line": 170, "call": "OpenSwoole\\Server::start()" } ] } } ] } ```

**Lighthouse Version** 6.34.1
danbka33 commented 4 months ago

The error only appears when used together with laravel octane (swoole). There is no error when using php-fpm.

danbka33 commented 4 months ago

Add dump to constuctor of SubscriptionRegistry

dump('subscription registry new instance: ' . spl_object_hash($this));

Got 2 instances

subscription registry new instance: 00000000000054960000000000000000
subscription registry new instance: 00000000000007ea0000000000000000

First request i got

array:1 [ // $subscriptions dump
  0 => "scheduleUpdated"
]
spl_object_hash of SubscriptionRegistry: 00000000000007ea0000000000000000

Second and future requests

array:0 [] // $subscriptions dump
00000000000054960000000000000000

In the second and etc requests, subscription registration is not called...

danbka33 commented 3 months ago

To fix this issue just add SubscriptionRegistry::class to octane config octane.warm.

Description of this configuration section.

    /*
    |--------------------------------------------------------------------------
    | Warm / Flush Bindings
    |--------------------------------------------------------------------------
    |
    | The bindings listed below will either be pre-warmed when a worker boots
    | or they will be flushed before every new request. Flushing a binding
    | will force the container to resolve that binding again when asked.
    |
    */

After adding this SubscriptionRegistry to the list of warms, the problem went away.

 'warm' => [
        ...Octane::defaultServicesToWarm(),
        Nuwave\Lighthouse\Subscriptions\SubscriptionRegistry::class,
    ],

It is worth updating the documentation and creating a section on how to configure lighthouse to work with laravel octane, or using internal methods to change the laravel octane configuration.

I'm still not entirely sure whether the decision is correct or whether there is some side effect from adding this class to the list of "warm".

danbka33 commented 3 months ago

Based on the explanations in this article, this appears to be a solution to the problem.

https://divinglaravel.com/laravel-octane-bootstrapping-the-application-and-handling-requests

Only singletons that are resolved during the application bootstrapping will persist between requests. Singletons that are resolved during request handling will be registered in the sandbox container, this container is destroyed after handling the request. To persist singletons between requests, you can either resolve them in your service providers or add them to the warm array inside the Octane configuration file

But the explanations sound a little strange, here singleton is set in the service provider, which in theory should be a marker for laravel octane to keep it persistent... https://github.com/nuwave/lighthouse/blob/28d04c9c3dfcb1a0809780f62f4cdf4a0abd8228/src/Subscriptions/SubscriptionServiceProvider.php#L30

spawnia commented 1 week ago

I propose an addition to the docs in https://github.com/nuwave/lighthouse/pull/2575, does this look right?