wahern / cqueues

Continuation Queues: Embeddable asynchronous networking, threading, and notification framework for Lua on Unix.
http://25thandclement.com/~william/projects/cqueues.html
MIT License
244 stars 37 forks source link

cqueues.lua:85 expected 1 arguments, got 5 #244

Closed cmouse closed 3 years ago

cmouse commented 3 years ago

Hi!

When using cqeues in Dovecot push notification lua driver, I get the following error:

doveadm(testuser): Error: lua: /home/cmouse/.luarocks/share/lua/5.3/cqueues.lua:85: expected 1 arguments, got 5

using following code

function dovecot_lua_notify_begin_txn(user)
  return {user=user}
end

function dovecot_lua_notify_end_txn(ctx, success)
  local cqueues = require("cqueues")
  local socket = require("cqueues.socket")

  local con = socket.connect("dovecot.org", 80)

  local inner = cqueues.new()
  local outer = cqueues.new()

  inner:wrap(function()
    con:write("GET / HTTP/1.0\n")
    con:write("Host: dovecot.org:80\n\n")

    for ln in con:lines() do
        dovecot.i_debug("a line")
    end
  end)

  outer:wrap(function()
    assert(inner:loop())
  end)

  assert(outer:loop())
end

function dovecot_lua_notify_event_message_append(ctx, event)
  dovecot.i_info("message appended")
end

function dovecot_lua_notify_event_message_new(ctx, event)
  dovecot.i_info("message delivered")
end

Any ideas what to do with this? To reproduce locally, you need to compile dovecot manually as it requires a patch to change how Lua scripts are handled.

daurnimator commented 3 years ago

Can you confirm that your cqueues.lua line 85 is the same as https://github.com/wahern/cqueues/blob/b0c2bc5979f008a39300b01a0dc3e967c6257be9/src/cqueues.lua#L85 ?

cmouse commented 3 years ago

Yes, I can confirm this.

cmouse commented 3 years ago

Forgot to mention, this is with lua5.3

daurnimator commented 3 years ago

We debugged on IRC; the issue was that dovecot was saving away a lua_State* and using that instead of the one passed to its C functions. All usage of coroutines was broken.