Giter VIP home page Giter VIP logo

Comments (4)

nvie avatar nvie commented on June 7, 2024 1

Thanks for the kind words. Believe it or not, but I've run into this very issue two days ago myself, and I have been meaning to investigate it more deeply. I'll try to take a look at it tomorrow, because you're right, and this replication is amazingly helpful! πŸ’―

from liveblocks.

nvie avatar nvie commented on June 7, 2024 1

Hey @dev-badace, I've opened a PR to fix this in #1463.

the ideal place to cleanup would be when machine exists the @connecting.busy. so right before the state is marked stale

Exactly. In this case, however, the @connection.busy is implemented as a promise-based state (because it uses .onEnterAsync()), which triggers a promise on enter, and will either (1) advance to @ok.connected when it resolves, or (2) handle any failure case otherwise.

The way the machine is constructed guarantees that socket is only observable/set when in the @ok.* states. Other states simply don't know about a socket instance by design. That why a cleanup function in the "on exit" handler for @connection.busy is less useful and may falsely suggest that socket is/can be set there.

So my fix is most in line with the ideal scenario: either the @connection.busy promise returns a succesful socket instance and advances to @ok.* sub states, or… an error happens and no traces are left behind. This fix takes care of the "leaving no traces behind" part, which was obviously missing here indeed.

Again, thanks for thinking along. Let me know what you think!

from liveblocks.

nvie avatar nvie commented on June 7, 2024 1

This fix is now published with v1.9.8.

from liveblocks.

dev-badace avatar dev-badace commented on June 7, 2024

I'm glad I was helpful. πŸ˜„

this is an interesting one. I'd like to also share a few solutions that came to my mind,

  1. taking a third cleanup function for stale success cases however this still can lead to >1 open websocket connections till the window it's cleared by the cleanup function

  2. a different variation of the above solution where the success case gets called with another argument boolean isStale, and checking for that, (hmm... i don't like this one).

the ideal place to cleanup would be when machine exists the @connecting.busy. so right before the state is marked stale

      return () => {
        cancelled = true;
        cleanup(this.current.context) //something like this, here we close the socket in context `tempSocket`
      };

maybe additional piece of info in the context like tempSocket that gets passed down to the cleanup via context.

from liveblocks.

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.