Repository navigation
Harden what happens when saving to the database fails - #1437
Merged
Merged
Conversation
Three gaps from the review of home-page: - A request failing inside create, update or delete left the transaction's completion promise rejecting with nobody listening, so each failure was reported a second time as an unhandled rejection. The promise is now marked handled; the caller still gets the request's error. - Closing a tab never warned once the database was in use, on the grounds that every edit is already stored. After a failed save that is not true. The storage now tracks which files a failed flush left unsaved, until they are next saved, and the tab warns before closing while any remain. - The cross-tab change handler refreshed the project list first and gave up if that failed, so a delete in another tab could go unnoticed. It now logs the failure and carries on to deal with the open project.
|
Preview build will be at |
A failed flush dropped its changes, keeping only the names of the files it had failed to save. So switching or creating a project lost them: the flush on switching sent only what was newly pending, and the new project's storage started with nothing unsaved, which ended the close warning too. With storage full, going to the projects page to delete something is the natural remedy, and one click on another project there lost the edit. A change now stays queued until a flush is known to have saved it. A failed flush still sets no timer of its own, so nothing retries for ever against a full quota, but the next flush, whatever causes it, carries everything still unsaved. That includes the one made when the project is switched. Unsaved changes are now simply that the last flush failed, in place of tracking files by name, and the warning clears on the next successful save of anything.
Keeping a failed save's changes for the next flush had side effects: - With the project open in two tabs, a failed save in one followed by any save in the other left the first out of step. It reloaded from the database, losing its edit from the screen, and then the outgoing storage wrote that edit to the database. The change handler now saves what this tab has outstanding before it reloads, taking the name from the database first as the name is the other tab's to change. If that still cannot be saved, the tab keeps its copy and does not reload. - A flush that failed because the project had been deleted was queued like any other, and the next urgent flush, which does not check the project exists, wrote part of it back. save() now rejects with NoSuchProjectError and the storage drops everything on that. - After a spell of failures the project was stamped with the first failed edit's time. It is now stamped with the latest edit's.
Opening the project that is already open took the reload path, which put the database's copy on screen before the outgoing storage flushed. After a failed save that lost the edit from the editor while the database gained it, and the next keystroke wrote the old content back. That is the path the queue was meant for: storage full, go to the projects page, free some space, click back into the project. The cross-tab handler already saved first and skipped the reload if that failed. That now lives in switchTo's reload branch, so it covers both. The handler asks for a reload and treats a project that is not there as deleted. Also corrects two comments that still said a failed flush's changes are dropped, and the overview on a tab that cannot save: it stays out of step until the project is opened in it again or the tab is reloaded.
Collaborator
Author
|
Happy with this now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Three gaps in what happens when a save to the projects database fails. From the
home-pagereview: the rest of finding 10, and smaller points S6 and S11.Unhandled rejections from failed writes
create,updateanddeleteawait each request in a transaction and thentx.done. When a request failed, the method threw before reachingtx.done, and the transaction's own rejection had nobody listening. So one failure was reported twice: once to the caller, and once more as an unhandled rejection in error reports.The transaction's promise is now marked handled when it is created. The caller still gets the request's error, and awaiting
tx.donestill rejects.save, which flushes use, already avoided this.A failed save is no longer the end of the edit
A failed flush dropped its changes. With the database in use the editor had also stopped warning before a tab closes, since every edit is already stored. So after a failed save the edit was in memory only, with the "Failed to save" toast as the only sign, and it was lost on closing the tab or on switching to another project.
Projects.hasUnsavedChangesexposes that for the open project, and the before-unload check uses it when the database is active. Without the database, and in iframe mode, the check is unchanged.Keeping changes queued has consequences elsewhere, which are handled:
switchTo, so both callers get it.save()rejects withNoSuchProjectErrorwhen the project has gone, and the storage then drops its queue. Otherwise the next flush from a hidden or unloading page, which does not check the project exists, would write part of it back.A cross-tab notice dropped when the list refresh fails
The change handler refreshed the project list first and gave up if that failed, as an unhandled rejection. A delete in another tab could then go unnoticed, leaving the editor on a project that no longer exists. It now logs the failure and carries on to deal with the open project.
For review
docs/tech-overview.mdis updated.