Network error once session is expired

AI-generated summary

Users keeping Discourse open for extended periods (weeks or months) encounter a “network error” when their session expires, especially if session timeout is set short (e.g., 1 hour). sebastien reports this issue occurs when users try to access topics or profiles after inactivity, and suggests redirecting them to the login/SSO page upon session expiry. codinghorror questions the need to reduce session duration from the default 60 days and notes browsers typically keep sessions alive via pings. sebastien clarifies users avoid closing tabs to prevent re-login. Falco confirms the issue, noting expired sessions cause silent failures in notifications and timing, and proposes enhancing Discourse.ajax to detect 302 redirects to /login and prompt users to refresh or log in — beneficial for enterprises with short sessions or tab-heavy users. fefrei links to a 2015 report on similar behavior, and Falco adds that the problem is now worse due to configurable short sessions, not just missed logout notifications.

Hi guys,

Some users tend to keep Discourse opened for weeks/months. Unfortunately, users get a “network error” when they are trying to browse the forum with an expired session.

I can easily reproduce this behavior by setting the session expiry time to 1 hour, wait 1 hour and try to open my profile or a topic… Eventually i would get this network error issue.

From my perspective, we should redirect the users to the login/sso page when their session is expired. Is there anyway to achieve that?

Thank,
Seb

Sorry for the noise, let’s start over here.

How long are they keeping the browser open, exactly, and on which page? The browser pings us periodically so it should stay alive pretty much forever.

If you don’t want sessions to expire, then why did you change the setting from its default of 1440 hours (that’s 60 days) to one hour?

Are you really telling us that you expect your users to keep the browser open for more than 60 days?

Hi,

Thank you for your answer. My beloved users never restart their computer and tend to have tons of tabs loaded. They keep the main page opened and then from time to time, they open topics/their profile… I don’t expect/want them to keep it opened but that’s what they are doing… When I tell them to close all tabs they answer me “no because then I will have to login again” :smile:

I would expect users to be redirected to the login/sso page once their session expires.

Sure @falco had an idea to follow up here but did not post it in public for some reason. Perhaps he should? :wink:

2 Likes

I had this exact same problem. That was one of the reasons I did the PR for a shorter session in the first place.

When the session cookies expires Discourse get’s crazy. A public topic will get loaded, but timings, notifications and everything will start to fail silently and will eventually break.

Ideally we would have a exception treatment in our Discourse.ajax function that would popup saying that the session expired, click to refresh/login.

This would help enterprise setups with small sessions (because of IT audits or shared computers) and tab hoarders alike.

We just need to be careful to capture this correctly. I think it’s when your xhr gets a 302 with location being ${Discourse.base_url}\login.

4 Likes

I think this is a duplicate of my very first bug report from back in 2015 :slight_smile:

1 Like

Yes. Now it’s a bit worse because you can have a session lifetime shorter than forever, so it’s not only when you miss a notification.

2 Likes