Skip to content

fix: Potential onCreateDocument race condition#167

Merged
hanspagel merged 3 commits intomainfrom
fix/on-create-document
Aug 20, 2021
Merged

fix: Potential onCreateDocument race condition#167
hanspagel merged 3 commits intomainfrom
fix/on-create-document

Conversation

@tommoor
Copy link
Contributor

@tommoor tommoor commented Aug 19, 2021

  • fix: Potential onCreateDocument race condition when multiple connections are formed simultaneously
  • fix: onChange callback triggered upon hydration of document from persistence

related #149

…rver

fix: 'onChange' callback triggered upon hydration of document from persistence
}

this.documents.set(documentName, document)
document.onUpdate(handleDocumentUpdate)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Binding of onChange callbacks after persisted state applied

const document = this.documents.get(documentName)
return resolve(document)
}
if (this.documents.has(documentName)) {
Copy link
Contributor Author

@tommoor tommoor Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the document exists already then it can be returned synchronously, avoiding any potential promise race conditions

this.handleDocumentUpdate(document, connection, update, request, connection?.socketId)
})
const document = new Document(documentName)
this.documents.set(documentName, document)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, similarly it should be added to the map synchronously

@tommoor tommoor requested a review from hanspagel August 19, 2021 19:49
@hanspagel hanspagel merged commit b3e3e4d into main Aug 20, 2021
@hanspagel
Copy link
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>
@hanspagel hanspagel deleted the fix/on-create-document branch October 5, 2021 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants