Code Monkey home page Code Monkey logo

Comments (6)

0xTim avatar 0xTim commented on June 2, 2024

@PatrickPijnappel what does your web socket code look like? We're probably missing a hop somewhere

from websocket-kit.

PatrickPijnappel avatar PatrickPijnappel commented on June 2, 2024

@0xTim Basically this:

self.queue.async {
    // (…)
    webSocket.onBinary { [weak self] _, data in // Called from arbitrary queue
        guard let self = self else { return }
        // (…)
    }
}

from websocket-kit.

0xTim avatar 0xTim commented on June 2, 2024

What is self in this instance and queue? Im assuming the web socket is being created outside of the queue closure?

from websocket-kit.

PatrickPijnappel avatar PatrickPijnappel commented on June 2, 2024

self is a custom (final) class and queue is a serial DispatchQueue. The web socket is being created elsewhere on another queue using effectively

WebSocket.connect(to: url, on: app.eventLoopGroup.next()) { webSocket in
    queue.async { self.webSocket = webSocket }
}

from websocket-kit.

0xTim avatar 0xTim commented on June 2, 2024

@PatrickPijnappel ah ok, I misread this initially.

Setting the WS callbacks must be done on the Websocket's EventLoop. We assumed this was the case before but had no way to enforce this at a compiler level before Sendable. Doing it off the event loop might have worked but could easily caused crashes before and for us to be Sendable compliant we have to enforce it.

One workaround might be to wrap your calls in

websocket.eventLoop.execute {
  websocket.onBinary {
    // ...
  }
}

That should enforce that the mutations are done on the correct event loop, but mixing concurrency, event loops and dispatch queues like this is always going to cause issues

from websocket-kit.

PatrickPijnappel avatar PatrickPijnappel commented on June 2, 2024

@0xTim Ah i see, thank you!

from websocket-kit.

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.