Skip to content

Laravel Octane Compatability #64

@yassir3wad

Description

@yassir3wad

Package version

v5.0.3

Describe the bug

When running the application with Octane (using Vapor + Octane), Laravel retains connection/service instances in memory between requests. However, upon terminating an operation, Laravel calls the connection’s disconnect() method, causing the connection to become null. Subsequent operations then encounter a null connection, resulting in an exception when attempting to call Elasticsearch operations.

{
    "message": "Call to a member function search() on null",
    "exception": "Error",
    "file": "/var/task/vendor/pdphilip/elasticsearch/src/Connection.php",
    "line": 614,
}

To Reproduce

  1. Deploy a Laravel application using Vapor with Octane enabled.
  2. Use the Elasticsearch package to perform operations.
  3. Observe that after an operation (where Laravel disconnects the service), any subsequent Elasticsearch call fails because $this->connection is null.

Expected behavior

Before executing any Elasticsearch operation (e.g., search(), select(), count(), etc.), the connection should be verified and reconnected if necessary. This behavior is similar to how the Laravel MySQL driver manages connections via the run method, ensuring a valid connection for every operation.
https://github.com/laravel/framework/blob/12.x/src/Illuminate/Database/Connection.php#L768

Actual Behavior:

After Laravel disconnects the connection post-operation, any subsequent Elasticsearch calls result in a Call to a member function search() on null error, due to the stale connection instance.

Proposed Fix:

Ensure that the reconnectIfMissingConnection() method is invoked before any internal Elasticsearch operation is executed within the Connection class. This will help maintain a valid connection state across operations when running with long-lived Octane workers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions