[stable26] fix: load fresh session if none are remaining #3891
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #3890
📝 Summary
When creating a new session
check for all existing sessions
to take those into account
that are only preserved because of unsaved changes.
It there still aren't any sessions
make sure to load a fresh editing session
even if there are unsaved steps.
These steps most likely originate from a race condition when closing the last editing session and pushing steps at the same time.
Background
We were seeing empty editing sessions in production while the markdown files had some content.
This was happening because there were some steps still around even though all sessions had been closed.
When the last session was closed
steps were pushed at the same time.
The push passed the session check before the session was cleared. The session data and the steps were cleared
and only then the new step was added.
This left the database in an inconsistent state:
Instead of trying to prevent this race condition
detect this state and recover from it.
Scenarios
Actual remaining changes
Sessions are sometimes aborted without close request in the middle of editing. In this case all steps are present in the database and the session also remains.
The session will not be cleaned up during
resetDocument. InsteadresetDocumentthrowsDocumentHasUnsavedChagesException.We can detect this scenario because even
removeInactiveSessionsalso takes remaining steps into account and leaves sessions with steps alone. Therefore sessions will remain inapiService->create(...)andfreshSessionwon't be set.Leftover steps from race condition
Steps are only cleaned up when the last active session is closed. Even if a few steps manage to sneak in after the clean up the session will be removed
and so
remainingSessionswill be empty duringcreate. ThereforefreshSessionwill be set and the content will be send out. The leftovers won't be cleaned up until the file has been saved again. But that should be fine. They will not impact the editing.🏁 Checklist
npm run lint/npm run stylelint/composer run cs:check)