Giter VIP home page Giter VIP logo

Comments (8)

jggc avatar jggc commented on May 24, 2024

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.

jggc avatar jggc commented on May 24, 2024

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.

hanspagel avatar hanspagel commented on May 24, 2024

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.

jggc avatar jggc commented on May 24, 2024

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.

tommoor avatar tommoor commented on May 24, 2024

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.

hanspagel avatar hanspagel commented on May 24, 2024

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.

jggc avatar jggc commented on May 24, 2024

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.

hanspagel avatar hanspagel commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.