Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Websockets suddenly stopped working #1059

Closed
iamsubingyawali opened this issue Nov 16, 2022 · 1 comment
Closed

Websockets suddenly stopped working #1059

iamsubingyawali opened this issue Nov 16, 2022 · 1 comment

Comments

@iamsubingyawali
Copy link

iamsubingyawali commented Nov 16, 2022

One day I realized that my web sockets are not working in my production Apache server. So, I tried to debug there and found nothing wrong, queues are working, socket clients are connecting but not receiving anything on clients side.

How? - No Idea
Since When? - No Idea

So, I decided to test it all in my local environment as I did earlier before deployment.

I am using below Vue.js code to debug my socket connection:

import Echo from "laravel-echo";
import Pusher from "pusher-js";
window.Pusher = Pusher;

const token = "44|yiPuLJM1DviFgX7Aq6cZPam86eyQMYoNssZQs2gl"
const tenant = "test"

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'laravel_rdb',
    wsHost: '127.0.0.1',
    authEndpoint: 'http://localhost/myapp/public/broadcasting/auth',
    encrypted: false,
    forceTLS: false,
    wsPort: 6001,
    wssPort:6001,
    disableStats: true,
    enabledTransports: ['ws', 'wss'],
    auth : {
        headers : {
            Authorization: "Bearer " + token,
            Accept: "application/json",
            'X-Tenant': tenant,
        }
    },
})

window.Echo.private(tenant + '.notifications.user.1')
    .listen('NotifyUser', (e) => {
    console.log(e)
})

window.Echo.connector.pusher.connection.bind('state_change', (state) => {
    console.log('Debug - Current connection state: ' + state.current);

    if (window.Echo.websocketsState !== '' && state.current === 'connected') {
        console.log("Status Update: " + state.current);
    } else if (window.Echo.websocketsState !== '' && state.current === 'failed') {
        window.Echo.reconnectInterval = window.setInterval(() => {
            var ifConnected = window.navigator.onLine;
            if (ifConnected) {
                clearInterval(window.Echo.reconnectInterval);
                console.log("Status Update 2: " + state.current);
            }
        }, 3000);
    }

    window.Echo.websocketsState = state.current;
});

Using this code, I can see that web socket is connecting successfully but console is not showing anything about my send messages.

I am using database queue to process socket messages and using php artisan queue:work I can see that my broadcast queues are being processed.

I tested with web sockets dashboard as well. I can see my channel as subscribed when I start my Vue.js code but when I try to send an event message to that channel from the dashboard it does nothing. No errors, no alerts, nothing.

I haven't done any changes to my web sockets code. The same code was working fine without any issues, but it suddenly stopped working and the most frustrating thing is that there are no errors at all.

Only possible error causing factor I am guessing is, compatibility issues with some dependent packages or Laravel framework itself as I update them regularly. It has been a long time since I have checked web sockets, so I am not really sure what might have caused the issue.

@iamsubingyawali
Copy link
Author

Duplicate issue #1041

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant