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

Connection Problems Due to Disconnection When Using Authentication #4498

Open
1 task done
jaluscg opened this issue Dec 5, 2024 · 0 comments
Open
1 task done

Connection Problems Due to Disconnection When Using Authentication #4498

jaluscg opened this issue Dec 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jaluscg
Copy link

jaluscg commented Dec 5, 2024

Duplicate Check

Describe the requested feature

I am trying to use authentication in my application, and it works correctly on web. However, when using a mobile device in the web, after completing the authentication process and being redirected to the authentication page, the server assumes the client has disconnected. As a result, the server immediately restarts.

This behavior causes a problem: when the authentication process finishes, the server has already disconnected the session. The client tries to reconnect, but the session has been terminated, resulting in errors.

I suspect the issue lies in the unregister function within client.go. The function currently disconnects the client immediately when the server detects a disconnection, without providing any grace period to determine if the client has simply navigated to another page temporarily.

Current Implementation of unregister:

func (c *Client) unregister(normalClosure bool) {
    log.Debugf("WebSocket client disconnected (normal closure=%t) from %s: %s", normalClosure, c.clientIP, c.id)
    stats.ClientDisconnected()

    if c.role == "" {
        return
    }

    // unsubscribe from pubsub
    pubsub.Unsubscribe(c.subscription)

    c.exitExtendExpiration <- true

    // unregister from all sessions
    if c.role == WebClient {
        for _, session := range store.GetClientSessions(c.id) {
            log.Printf("Unregistering web client %s from session %s:%s", c.id, session.Page.Name, session.ID)
            store.RemoveSessionWebClient(session.Page.ID, session.ID, c.id)
            sendPageEventToSession(session, "disconnect", "")
        }
    }

    // unregister host client from all pages
    if c.role == HostClient {
        for _, page := range c.pages {
            c.unregisterPage(page)
        }
    }

    // unregister web client from a page name
    if c.role == WebClient {
        for pageName := range c.pageNames {
            store.RemovePageNameWebClient(pageName, c.id)
        }
    }

    // expire client immediately
    if normalClosure {
        deleteExpiredClient(c.id, true)
    }
}

Suggest a solution

The unregister function could be modified to introduce a delay before fully disconnecting the client. This delay would allow time to check whether the client is reconnecting or has simply navigated to another page momentarily. For instance, a timeout of one minute could prevent unnecessary disconnections and improve the user experience during authentication.

Screenshots

No response

Additional details

No response

@ndonkoHenri ndonkoHenri added the bug Something isn't working label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants