🐛 Wrong error when submitting ops during hard rollback.#692
Merged
dawidreedsy merged 2 commits intomasterfrom Mar 4, 2025
Merged
🐛 Wrong error when submitting ops during hard rollback.#692dawidreedsy merged 2 commits intomasterfrom
dawidreedsy merged 2 commits intomasterfrom
Conversation
70e8163 to
d6842e4
Compare
alecgibson
reviewed
Mar 4, 2025
Comment on lines
+753
to
+757
| if (this._isInHardRollback) { | ||
| var err = new ShareDBError( | ||
| ERROR_CODE.ERR_DOC_IN_HARD_ROLLBACK, | ||
| 'Cannot submit op. Document is performing hard rollback. ' + this.collection + '.' + this.id | ||
| ); |
Collaborator
There was a problem hiding this comment.
You could just move this after the var err = new ShareDBError(ERR_DOC_DOES_NOT_EXIST) to override this "default" error and then avoid having to duplicate the emit() machinery
Contributor
Author
|
Yes i know want to prepare the test today, just need to fiddle a bit to make it work. Just wanted to push it first, so the @ericyhwang get a chance to look into it before the meeting :) |
a8e8f0c to
814e814
Compare
After doing the steps:
1. Create a doc with rich text type (or any other non irreversible type)
2. Make op submission fail
3. Now in the hard rollback we do `this._setType(null);`
4. If there is any op comming before the hard rollback `fetch` is finished, we get the error
```
Cannot submit op. Document has not been created.
```
as in the `_submit` we do:
```typescript
if (!this.type) {
var err = new ShareDBError(
ERROR_CODE.ERR_DOC_DOES_NOT_EXIST,
'Cannot submit op. Document has not been created. ' + this.collection + '.' + this.id
);
if (callback) return callback(err);
return this.emit('error', err);
}
```
We definitely do not handle this case properly. Possible solutions:
1. Just throw error whenever that happens, which is easy to implement
and it is not really breaking. User would be then able to react on
the error or just ignore it.
2. Store copy of cannonical snapshot in the doc itself, so that we do
not have to do fetch for hard rollback. More difficult to implement
and has a side effect of storing the doc twice in the memory.
814e814 to
6f3869c
Compare
Contributor
Author
|
To be honest i think there might be more to this than just my fix as before fetch we do this._setType(null);
this.version = null;
this.inflightOp = null;
this.pendingOps = [];and after fetch is finished if (inflightOp) pendingOps.unshift(inflightOp);
var allOpsHadCallbacks = !!pendingOps.length;
for (var i = 0; i < pendingOps.length; i++) {
allOpsHadCallbacks = util.callEach(pendingOps[i].callbacks, err) && allOpsHadCallbacks;
}
if (err && !allOpsHadCallbacks) doc.emit('error', err);
doc._isInHardRollback = false;
```,
I think it was menat to reject all ops that were added after fetch started. I am not sure just throwing the above error wouldn't break anything. Even though all tests are passing. |
ericyhwang
reviewed
Mar 4, 2025
lib/client/doc.js
Outdated
|
|
||
| if (!pendingOps.length) return; | ||
| if (!pendingOps.length) { | ||
| doc._isInHardRollback = false; |
Contributor
There was a problem hiding this comment.
If we want to avoid potential future issues with forgetting to reset _isInHardRollback on early returns, we could reset to false at the top of this _fetch callback
0857be5 to
fd67b16
Compare
ericyhwang
approved these changes
Mar 4, 2025
dawidreedsy
added a commit
that referenced
this pull request
Mar 6, 2025
Similar case to: - #692 however instead of submitting ops to doc is when we submit doc presence
dawidreedsy
added a commit
that referenced
this pull request
Mar 6, 2025
Similar case to: - #692 however instead of submitting ops to doc is when we submit doc presence
longlonggoo
added a commit
to longlonggoo/longlonggoo
that referenced
this pull request
Aug 13, 2025
… (#693) Similar case to: - share/sharedb#692 however instead of submitting ops to doc is when we submit doc presence
FernhillFable
added a commit
to FernhillFable/cluster
that referenced
this pull request
Aug 13, 2025
… (#693) Similar case to: - share/sharedb#692 however instead of submitting ops to doc is when we submit doc presence
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.
After doing the steps:
this._setType(null);fetchis finished, we get the erroras in the
_submitwe do:We definitely do not handle this case properly. Possible solutions: