GeniusesOfSymfony / WebSocketBundle

:part_alternation_mark: Websocket server for Symfony applications (powered by Ratchet), includes a Autobahn.JS based JavaScript client
MIT License
609 stars 140 forks source link

Session Problem PDO #465

Closed ma-gu-16 closed 2 years ago

ma-gu-16 commented 2 years ago

Error: The service "session.storage.native" has a dependency on a non-existent service "@session.handler.pdo".

Config like https://github.com/GeniusesOfSymfony/WebSocketBundle/blob/3.x/docs/authentication.md

Symfony: 4.4

Is this Documentation still right ?

Thank you.

mbabker commented 2 years ago

Yes, it's still accurate. The examples on that page use the session.handler.pdo service defined in the snippet under the https://github.com/GeniusesOfSymfony/WebSocketBundle/blob/3.x/docs/authentication.md#session-authentication section. Use whatever service ID corresponds to the session handler your application is actually using.

ma-gu-16 commented 2 years ago

Yes if i do it like you described , i got the above error...

it only works when i configure pdo sessions like the synfony doc: https://symfony.com/doc/4.4/session/database.html

but then i got mysql has gone away errors sometimes from websocket :(

mbabker commented 2 years ago

Ratchet doesn't support all of the session handlers that Symfony ships with, so you have to use one of the ones it will support (generally anything except the native filesystem-based handlers will work, i.e. the database or Redis).

For the MySQL issue, add this to your config (I forgot to add this section to the docs), it'll run a ping type query at a configured interval (default is 20 seconds) to keep the connection alive:

gos_web_socket:
    ping:
        services:
            -
                name: 'database_connection'
                type: 'doctrine'
                interval: 20 # This line's optional, only needed if you want to adjust the ping interval
ma-gu-16 commented 2 years ago

Yep this works... the Erros seems to be gone. Thank you.

My Config looks like this now:

gos_web_socket:
  authentication:
    enable_authenticator: true
    providers:
      session:
        firewalls: ['main'] 
        session_handler: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler

  ping:
    services:
      -
        name: 'database_connection'
        type: 'doctrine'
        interval: 20 # This line's optional, only needed if you want to adjust the ping interval
framework:
  session:
    handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
    gc_maxlifetime: 36000
    cookie_secure: auto
    cookie_samesite: lax
services:
  Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
    arguments:
      - '%env(DATABASE_URL)%'
      - { db_table: 'user_session', lock_mode: 0 }

Maybe add this to your Docs ? I Use Symfony 4.4. flex

ma-gu-16 commented 2 years ago

Still does not work :-(

[2022-06-30 15:33:08] websocket.ERROR: An error occurred while attempting to secure topic "App\Websocket\Topics\SecuredTopicHandler", the connection was rejected: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away {"exception":"[object] (PDOException(code: HY000): SQLSTATE[HY000]: General error: 2006 MySQL server has gone away at /var/www/webroot/ROOT/vendor/symfony/http-foundation/Session/Storage/Handler/PdoSessionHandler.php:630)"} []