GeniusesOfSymfony / WebSocketBundle

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

Disconnected for Connection lost - scheduled 1th reconnect to occur in 5 second(s). with code 6 #351

Closed klodoma closed 5 years ago

klodoma commented 5 years ago

Hi Guys,

I am looking around since a while for a solution on this. The client gets constantly disconnected after connect. There are several reports on this, but I couldn't find a solution for it.

I am using the examples provided here: https://github.com/GeniusesOfSymfony/WebsocketAppDemo

I was trying to setup WebSocketBundle on Symfony 4.1 and it works ONLY if I use the the "dev-master" version of the "gos/web-socket-bundle". With 1.8.3, 1.9* (all rc versions) it fails to work.

I am constantly getting the console message in the browser Disconnected for Connection lost - scheduled 1th reconnect to occur in 5 second(s). with code 6

The console of the gos:websocket:server looks like this: screenshot_229

If I switch to the "dev-master" version of the "gos/web-socket-bundle", then everything works well.

Is this a known issue? Any solution to get 1.8.3 working with Symfony 4.1?

I can provide more details if required. Thanks in advance!

konshensx16 commented 5 years ago

Well the console is not repporting any errors, just one thing i noticed is that th user is annonm if you ever happen to set up an authentication system make sure to run you symfony app using 127.0.0.1 otherwise it wont workm because it wont recognize the "localhost" name, just throwing this out there because it caused some problems for me when i was starting out with GOS.

klodoma commented 5 years ago

Well the console is not repporting any errors, just one thing i noticed is that th user is annonm if you ever happen to set up an authentication system make sure to run you symfony app using 127.0.0.1 otherwise it wont workm because it wont recognize the "localhost" name, just throwing this out there because it caused some problems for me when i was starting out with GOS.

Thanks for the info! Is your setup running with Symfony 4?

konshensx16 commented 5 years ago

Yes i have it with symfony 4, the project is actually in my public repos if you want to check it out it's called "Fabour", it's nothing fancy but has most of the functionalities of GOS in place and working.

klodoma commented 5 years ago

Yes i have it with symfony 4, the project is actually in my public repos if you want to check it out it's called "Fabour", it's nothing fancy but has most of the functionalities of GOS in place and working.

Thanks for the info. I'll have a look!

mbabker commented 5 years ago

The "user firewall is not configured" messages mean you need to set up the firewall in the bundle config.

gos_web_socket:
    client:
        firewall: [ main ] # This is the line you must configure to silence the firewall message
        session_handler: '%app_session_handler%'
        storage:
            driver: '@cache.websocket' # This is using symfony/cache and defined under the framework.cache.pools node
            decorator: '@gos_web_socket.client_storage.symfony.decorator'
            ttl: 0
jjsaunier commented 5 years ago

May be should we not set a default firewall, and raise an error in console to be more explicit ? I thought warning was enough :D

At the beginning I took that approach for beginner and having something working without a lot configuration.

klodoma commented 5 years ago

Those settings, do not fix the problem. I will create a repository with the problem, not sure why it's happening. Feedback will follow.

klodoma commented 5 years ago

I created this repo, it's the latest Symfony4 Setup(4.2.0) with defaults and I've added the WebSocketBundle

https://github.com/klodoma/symfony4-websocket

composer update
php bin/console server:run
php bin/console gos:websocket:server

If I open the index page, I use the sample code to connect to the websocket. It connects, but it doesn't work right.

I get repeated messages in the console: Disconnected for Connection lost - scheduled 1th reconnect to occur in 5 second(s). with code 6 On the server side, it seems to create a new client every time.

I hope this helps to debug a bit.

screenshot_231 screenshot_230

klodoma commented 5 years ago

I have found the issue. I've had these missing in services.yaml.

    # RPC handlers need to have the `gos_web_socket.rpc` tag, so by convention we will tag all handlers in the directory
    AppBundle\Rpc\:
        resource: '../../src/AppBundle/Rpc'
        tags:
            - { name: gos_web_socket.rpc }

    # RPC handlers need to have the `gos_web_socket.topic` tag, so by convention we will tag all handlers in the directory
    AppBundle\Topic\:
        resource: '../../src/AppBundle/Topic'
        tags:
            - { name: gos_web_socket.topic }
krajcikondra commented 2 years ago

I have same issue :-( but my services.yaml is correct. How did you find your problem? Is there some function cause disconnect the client which can I debug?

I have no idea how find where is the problem :-(

I am using Symfony 5.2 and gos/web-socket-bundle 3.9.0

krajcikondra commented 2 years ago

With gos/web-socket-bundle 3.14.0 same problem

krajcikondra commented 2 years ago

Fixed by ping mechanism. I created PingTopic and in javascript send ping message every 15 seconds and problem disappear. I have suspicion that ws connection was killed by browser if no messages send longer time.

I created javascript package which automatically solve ping in interval.

https://www.npmjs.com/package/gos-socket-client https://github.com/krajcikondra/gos-socket-client