Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket objects do not allow for receiving and sending at the same time #66

Closed
filiptibell opened this issue Jul 16, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@filiptibell
Copy link
Collaborator

Due to web socket objects aquiring an exclusive lock, this piece of code currently does not work:

local task = require("@lune/task")
local net = require("@lune/net")

local socket = net.socket("wss://...")

task.spawn(function()
    while true do
        local message = socket.next()

        -- ...
    end
end)

task.defer(function()
    print("0")

    -- This will yield indefinitely since `socket.next` completely locks the socket
    socket.send(...)

    print("1")
end)

I see two possible solutions here:

  1. Split the websocket into send & receive parts, lock them separately when their methods are called
  2. Handle receiving/sending of messages internally, not directly exposing it to lua. This would mean wrapping the websocket in some kind of message queue so that when we call next from multiple lua threads, and receive a message, all waiting lua threads will get the same message

The second solution seems more robust to me but may also require us to integrate with the async scheduler in some capacity

@filiptibell
Copy link
Collaborator Author

Fixed in #68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant