fix: Potential onCreateDocument race condition#167
Merged
Conversation
…rver fix: 'onChange' callback triggered upon hydration of document from persistence
tommoor
commented
Aug 19, 2021
packages/server/src/Hocuspocus.ts
Outdated
| } | ||
|
|
||
| this.documents.set(documentName, document) | ||
| document.onUpdate(handleDocumentUpdate) |
Contributor
Author
There was a problem hiding this comment.
Note: Binding of onChange callbacks after persisted state applied
| const document = this.documents.get(documentName) | ||
| return resolve(document) | ||
| } | ||
| if (this.documents.has(documentName)) { |
Contributor
Author
There was a problem hiding this comment.
If the document exists already then it can be returned synchronously, avoiding any potential promise race conditions
tommoor
commented
Aug 19, 2021
| this.handleDocumentUpdate(document, connection, update, request, connection?.socketId) | ||
| }) | ||
| const document = new Document(documentName) | ||
| this.documents.set(documentName, document) |
Contributor
Author
There was a problem hiding this comment.
Otherwise, similarly it should be added to the map synchronously
Contributor
|
Looks good! |
hanspagel
added a commit
that referenced
this pull request
Aug 20, 2021
* server: refactor incoming message handling * server: handle unknown messages more graceful * playground: disable onAuthenticate demo * provider: remove useless second parameter * server: move message handling logic to the message receiver * refactor the whole message handling (wip) * refactoring * refactoring * mute exceptions in the provider message receiver (wip) * reenable readOnly connections * clean up tests * docs: update all links from the overview to the single hook, fix #169 * fix: Potential onCreateDocument race condition (#167) * fix: Potential onCreateDocument race condition on highly contested server fix: 'onChange' callback triggered upon hydration of document from persistence * add test * refactor * Use onAuthenticate hooks from custom extensions, see #170 (#172) * use onAuthenticate hooks from custom extensions * simplify the check for the onAuthenticate hook * server: refactor incoming message handling * server: handle unknown messages more graceful * playground: disable onAuthenticate demo * provider: remove useless second parameter * server: move message handling logic to the message receiver * refactor the whole message handling (wip) * refactoring * refactoring * mute exceptions in the provider message receiver (wip) * reenable readOnly connections * clean up tests Co-authored-by: Tom Moor <tom.moor@gmail.com>
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.
onCreateDocumentrace condition when multiple connections are formed simultaneouslyonChangecallback triggered upon hydration of document from persistencerelated #149