Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket keeps connecting and disconnecting #97

Open
nosisky opened this issue Apr 4, 2024 · 4 comments
Open

Websocket keeps connecting and disconnecting #97

nosisky opened this issue Apr 4, 2024 · 4 comments

Comments

@nosisky
Copy link

nosisky commented Apr 4, 2024

I am having an issue where websocket keeps disconnecting and reconnecting, in my main.wasp file websocket autoconnect is set to true I am getting the below message:

{"code":1,"message":"Session ID unknown"}
Screenshot 2024-04-05 at 00 16 08

@vincanger
Copy link
Collaborator

hey @infomiho are you aware of this?

@Martinsos
Copy link
Member

I am having an issue where websocket keeps disconnecting and reconnecting, in my main.wasp file websocket autoconnect is set to true I am getting the below message:

{"code":1,"message":"Session ID unknown"} Screenshot 2024-04-05 at 00 16 08

Any more info you could provide? Type of app, any interesting code? Minimal code example where you can replicate this? Any other info that might help us to replicate this?

@nosisky
Copy link
Author

nosisky commented Apr 8, 2024

I have tried using the autoConnect: true in main.wasp file to make websocket always connected but that didn't help, I switched to using the below useEffect to manually start socket for the component that needs it but this keeps disconnecting also.

 useEffect(() => {
    const handleConnect = () => {
      console.log('Connected to server');
    };

    const handleDisconnect = () => {
      console.log('Disconnected from server');
    };

    // Connect the socket if not already connected
    if (!isConnected) {
      socket.connect();
    }

    // Listen for connect and disconnect events
    socket.on('connect', handleConnect);
    socket.on('disconnect', handleDisconnect);

    // Clean up event listeners and disconnect when component unmounts
    return () => {
      socket.off('connect', handleConnect);
      socket.off('disconnect', handleDisconnect);
      socket.disconnect();
    };
  }, []);

it disconnects and reconnects multiple times before becoming stable.

@Martinsos
Copy link
Member

Thanks!

Additioanl info that might help:

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

No branches or pull requests

3 participants