getgrav / grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
https://getgrav.org
MIT License
14.39k stars 1.39k forks source link

Loss of edits due to page expiry #3431

Open tg-x opened 2 years ago

tg-x commented 2 years ago

After editing a page for a long time and then clicking save, grav sometimes decides that the page expired (shows a Page expired error), and reverts the page to the last saved state, discarding all the unsaved edits without giving any chance to save it. Needless to say, this is incredibly frustrating, the user should be offered with the option to save the page anyway (or at least copy the text, so that it can be merged manually if the page changed since)

archfrog commented 2 years ago

I've experienced this problem a number of times myself. I tend to write for hours so this is definitely a big issue to me. I just lost a very technical description of an issue because I got the loathed Page Expired message (I had forgotten about the "Page Expired" issue because I haven't written anything for long while).

My system.yaml file says expires: 604800, yet I run into this problem after a relatively short time (say, 10 minutes). I'm not sure if this is the correct setting, though.

This issue should probably be bumped way up because it effectively makes Grav unusable for longer texts. I'd really hate to have to install WordPress or Drupal just to avoid getting "Page Expired" errors.

w00fz commented 2 years ago

Granted this seems definitely to be a bug. I just wanted to point out 2 things:

  1. There is a keepAlive feature supposed to be running in admin continuously which, like the name suggests, ensure the session never expires if you are logged in. Somehow it appears this is either no longer working or Grav expires anyway which is a potential issue.
  2. @archfrog that system.yaml timeout is only helpful for sessions in frontend, what you want to change is the Admin plugin configuration. /admin/plugins/admin -> Timeout: set this to a higher expiration timeout and see if it helps.

Please try to keep the browser inspector open, under the Network panel. When your session is about to expire you should see a keepAlive request going out that will ensure your session doesn't expire. Perhaps you are getting errors or this is not triggered. It would be very helpful to know what are your results and under which admin location this happens (I am assuming Flex Page editing?).

archfrog commented 2 years ago

@w00fz, thanks for your very quick reply!

My /admin/plugins/admin -> Timeout value was set at 1800 (30 minutes). I'm almost sure that is the culprit. As for the "10 minutes" I mentioned above, that number is probably wrong. When I write, I sort of loose track of all time.

I'll give it a try and report back within a few days whether or not changing Timeout to, say, 7200 has fixed the issue.

Is there any particular reason why the timeout value is set at such a low value? I'm pretty sure I'm using the default value.

w00fz commented 2 years ago

It shouldn’t matter because it’s not really supposed to expire, thanks to that keepAlive functionality I mentioned. The session timeout is as a safety measure in case you lose connectivity or your computer goes to sleep, etc.

I think somehow keepAlive is just not doing its job for you and I’m not entirely sure why unless we get more info about it. I can tell you I have several admin open on a daily basis that I resume working on in the morning and keepAlive seems to be doing fine for me as I never have to re-login, I’ll pay extra attention tomorrow morning (as I’m PT), to see if I catch anything odd.

Sorry for this issue, nothing more frustrating than being in the zone writing, only to lose all of your hard work. This is definitely not the expected behavior.

archfrog commented 2 years ago

It is okay, I have plenty of spare time and my general experience is that text gets better for each iteration :-)

I'm using Google Chrome and have opened the Developer Tools, Network . I've been writing a longer text after I changed Timeout to 7200, and no problem so far. I simply open a page in the Admin panel, by navigating to it, and type Markdown text into it. I suppose that means I'm using Flex Edit.

But I think you're right about keepAlive. I haven't seen a single request in the Network pane yet. I suppose it is named keepAlive, but there's absolutely nothing until I hit the Save button. How frequently should this keepAlive request occur?

w00fz commented 2 years ago

The frequency of keepAlive is dependent on your configured admin timeout and is calculated as keepAlive / 1.5. This is so that it anticipates the timeouts from happening by extending the session life.

By the way, I ensured to check this morning the Admin I left open last night, and it was fine. One thing I tried also, was to set my admin timeout to 30 secs. I then kept the browser inspector open on the network panel and observed for a few minutes.

This is what you should be seeing, can you try and report back?

w00fz-2021-10-18_@_08 54 09@2x
archfrog commented 2 years ago

I just tried changing the admin timeout to 30 secs, loading up a page in the editor, and wait a bit. I do get a task:keepAlive event every twenty or thirty seconds, no problem there. They all report status 200. Not sure what's going on.

forestrf commented 2 years ago

I've also had the problem. Maybe the browser is using power saving features? or the server failing to respond just on that specific call. If a keepalive task fails, will another one be performed? If not, will the session just end there? It would be pretty cool if the session could be kept open instead of using keep alive, as an option when logging in, like "remember", that would mean the user wants the session to stay open (though this is a patch for this specific problem, more of a solution to a different problem)