Comments (8)
I kept investigating and I think my assumption above is wrong, it seems to be a timing issue caused by my authentication on the server happening before handing over the connection to hocuspocus and after the websocket connection is established.
So there still is a bug but the repro steps may be different from the above.
from hocuspocus.
Nailed it down : when the websocket connection is handed over to hocuspocus not quickly enough (more than about 10 millis), hocuspocus (or y-websocket server?) will miss the first message(s) sent by the client and will never properly sync.
So a way I can 100% repro is :
app.ws('/:document', (websocket: ws, request: Request) => {
setTimeout(() => {
hocuspocus.handleConnection(websocket, request, request.params.document)
}, 1000); // <=== removing or reducing the timeout to below 10 ms fixes it every time and a timeout of 1s causes the bug every time
})
The fact that the first message is missed causes the client to never properly sync. The client side websocketProvider.on('sync', ...)
event is not fired. Sometimes the document data is still sent properly but its really not reliable.
@hanspagel sorry for my initial report not being 100% accurate it was a tricky one for me who doesn't know Y.js or CRDTs at all.
from hocuspocus.
No worries, it's a great bug report. One question though: Are you on the latest @hocuspocus/server version? I thought this is fixed.
from hocuspocus.
You made me doubt for a second since rocksdb extension is alpha.59 and my server is alpha.58 but from npmjs it really seems to be latest and I checked my source of truth :
cat node_modules/@hocuspocus/server/package.json
{
"name": "@hocuspocus/server",
"description": "plug & play collaboration backend",
"version": "1.0.0-alpha.58",
from hocuspocus.
when the websocket connection is handed over to hocuspocus not quickly enough (more than about 10 millis), hocuspocus (or y-websocket server?) will miss the first message(s) sent by the client
This kind of makes sense to me, if there's a time between setting up the connection and letting hocuspocus know about it then it seems like it would be upto the surrounding application to capture and enqueue messages that come in that time? It might mean that handleConnection
would need an optional parameter to accept messages that were queued.
from hocuspocus.
Makes sense to me, too! But the question for me is: Why should there be time between setting up the connection and letting hocuspocus know about it?
If there is a valid use case, I can add a parameter to pass queued messages. ✌️
You’re using Express, right? You’d probably need to set up the queuing yourself then though.
from hocuspocus.
It's been a little while since I've messed with this but my use case was to handle authentication before involving hocuspocus at all. Since I have to validate authentication against a remote provider it takes time and would mess up the message order.
My first idea when I opened this bug is that hocuspocus server should send some sort of hocuspocus is ready
event to signal the client that he is handling the connection.
My thought process behind this is :
- It's the client's responsibility to request the http(s)+ws connection whenever he is ready to do so
- It's the server's responsibility to tell the client when he is ready to handle commands over the websocket after he is fully satisfied with the client's request and has done all required validations if any
- At this point the bi-directional handshake is complete and they both are ready to exchange further messages
That said, I worked around it by using a hook (onConnect IIRC) and it's fine this way, I'm honestly not sure if there is a valid use case for messing with the connection before handing it over but I still think that it would make sense to have the server explicitly tell the client that he's ready when the connection is handed over.
Either way I'm fine with or without this feature so feel free to close if you feel it's not relevant enough.
from hocuspocus.
Thanks for getting back! I see your point, but yes, I think it’s better to handle the authentication in hocuspocus.
I’m closing this as I don’t think I’ll work on this soonish. But for everyone reading this: Feel free to comment, if there’s interest I’ll deal with it.
Thanks again for the report @jggc!
from hocuspocus.
Related Issues (20)
- Hocuspocus >=2.7.0 does not work with React in strict mode / Lexical HOT 5
- Support logging request/socket information in custom Logger.log function HOT 1
- Unsure how to fallback gracefully from initial provider connection issues HOT 2
- Migrate from slate js to prosemirror HOT 1
- Unnecessary onStoreDocumentHooks call on last connection close (potential data loss) HOT 1
- Provider downloads document content twice when syncing initially HOT 1
- Hang caused by not cleaning up Awareness in provider HOT 1
- Do collaboration history and auto-versioning work? HOT 1
- Add custome field to the Webhook
- Provider.disconnect prevents subsequent provider.connect from working HOT 1
- 2.10.0 breaks provider in nodejs HOT 7
- The server document judgment is always empty, resulting in duplicate data. HOT 2
- backend onChange undefined HOT 2
- Server crashed when webhook receives 400 status code response HOT 3
- Inaccurate document type check in onLoadDocument
- use lexical TypeError: The encoded data was not valid for encoding utf-8 HOT 1
- Updates made using openDirectConnection are not synchronizing changes across different Redis instances. HOT 9
- provider.destroy will reopen connection HOT 2
- About the actual storage size of documents during collaborative editing HOT 8
- An authentication token is required, but you didn’t send one - but token was actually included HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hocuspocus.