Closed pxyove closed 1 year ago
local function ioloop_recv(self)
return coroutine_resume(self.connection.coro)
end
-- Perform one input/output iteration, called by ioloop
function client_mt:_ioloop_iteration()
-- working according state
local loop = self.ioloop
local args = self.args
local conn = self.connection
if conn then
-- network connection opened
-- perform packet receiving using ioloop receive function
local ok, err
if loop then
ok, err = self:_io_iteration(ioloop_recv) -----------enter this branch
else
ok, err = self:_sync_iteration()
end
........
end
function client_mt:_io_iteration(recv)
local conn = self.connection
-- first - try to receive packet
local ok, packet, err = recv(self) -------finally stuck in here
-- print("received packet", ok, packet, err)
...
end
Please write in English in this repo
What connector are you using? Without it, the blocking luasocket functions will be used
What connector are you using? Without it, the blocking luasocket functions will be used
I use default connector,but I have two devices, same code, one communicating normally and the other having this problem,
Actually, if you're using a default connector, this is expected behavior to block the whole OS thread on recv() calls. This means no other code (C or Lua) will run in this OS thread until the next MQTT packet is received from the server.
As I can see from your code (by the way, please fix formatting by triple `-char), you're trying to call skyned.yield() after MQTT ioloop iteration. I suspect this will not work at all with the default connector.
I'm not familiar with the skynet module. Do you have some async networking (TCP connections) support in it? It might be wise to write a connector based on it, just like in ngxsocket.lua
Actually, if you're using a default connector, this is expected behavior to block the whole OS thread on recv() calls. This means no other code (C or Lua) will run in this OS thread until the next MQTT packet is received from the server.
As I can see from your code (by the way, please fix formatting by triple `-char), you're trying to call skyned.yield() after MQTT ioloop iteration. I suspect this will not work at all with the default connector.
I'm not familiar with the skynet module. Do you have some async networking (TCP connections) support in it? It might be wise to write a connector based on it, just like in ngxsocket.lua
Thank you very much. I will try other connectors first to see if I can solve this problem
Actually, if you're using a default connector, this is expected behavior to block the whole OS thread on recv() calls. This means no other code (C or Lua) will run in this OS thread until the next MQTT packet is received from the server. As I can see from your code (by the way, please fix formatting by triple `-char), you're trying to call skyned.yield() after MQTT ioloop iteration. I suspect this will not work at all with the default connector. I'm not familiar with the skynet module. Do you have some async networking (TCP connections) support in it? It might be wise to write a connector based on it, just like in ngxsocket.lua
Thank you very much. I will try other connectors first to see if I can solve this problem
May I ask you? I tracked the code further and found that it ended up here
function client_mt:_apply_network_timeout()
....
local sync_recv_func = conn.recv_func
conn.recv_func = function(...)
while true do
local data, err = sync_recv_func(...)
if not data and (err == "timeout" or err == "wantread") then)
loop.timeouted = true
coroutine_yield(err)
skynetco.yield(err)
else
return data, err
end
end
end
....
self.connection.recv_func = connector.receive() ------finally, block in here, is this correct?
I used default connector, so block in function luasocket.receive()
....
sorry, I didn't get the format right
Yes, the luasocket.receive()
call blocks the OS thread.
sorry, I didn't get the format right
I mean please enclose your code samples into `-char repeated 3 times to make block of code
But I set the ioloop timeout to one second and it didn't seem to work, so is block,why? Two devices same code, one working, one not working. I'll keep track. Thank you very much.
I tried to do that, but two devices luasocket.send one and luasocket.receive three data, they are same. Thank you very much. I'll keep track.
- Try to uncomment print() debug code in luasocket.send() and luasocket.receive() functions to track MQTT traffic, maybe you can find a difference for the two devices
- Try to set timeout to 0.1
Do you know the luasocket.settimeout of timeout where take effect and check. Because I'm suspicious of timeout no work
function luasocket.settimeout(conn, timeout)
conn.timeout = timeout
conn.sock:settimeout(timeout, "t")
end
I mean
local mq_loop = ioloop.create {
timeout = 0.1,
...
}
I mean
local mq_loop = ioloop.create { timeout = 0.1, ... }
I tried to do that, but two devices luasocket.send one and luasocket.receive three data, they are same.
Sorry, accidentally hit Closed ioloop itself is non-blocking,but now it is blocking,I want to know where to check timeout(default 0.005) and take effect, do you know where ?
Sorry, accidentally hit Closed ioloop itself is non-blocking,but now it is blocking,I want to know where to check timeout(default 0.005) and take effect, do you know where ?
Sorry, I cannot understand you
Did you try to uncomment network packet print()-traces as I advised?
Sorry, accidentally hit Closed ioloop itself is non-blocking,but now it is blocking,I want to know where to check timeout(default 0.005) and take effect, do you know where ?
Sorry, I cannot understand you
Did you try to uncomment network packet print()-traces as I advised?
Yes, I've tried that,two devices luasocket.send and luasocket.receive data is same
I mean, ioloop itself is non-blocking,but now it is blocking, maybe timeout no effective, Do you know where it effect?
local mq_loop = ioloop.create {
timeout = 0.1,
}
Timeout is applied to the luasocket's socket at https://github.com/xHasKx/luamqtt/blob/master/mqtt/luasocket.lua#L46 Can you please describe in more detail, what do you mean by "but I have two devices, same code, one communicating normally and the other having this problem". Does your code is blocked (i.e. code other than luamqtt does not run at all) or do you get disconnected from the broker on the second device?
I'm sorry. I've been on vacation. After I traced Luasocket deeply, I found that timeout in Luasocket did not take effect. I will reply to you when I solve this problem. Thank you very much.
Thank you for everyone, I have found out the cause of the problem(system-called connect/recv ret=-1,errno=0), It's caused by compile options error for LINUXTHREADS_OLD=y in uClibc-0.9.33.2.so .config, should select UCLIBC_HAS_THREADS_NATIVE=y.
for https://github.com/cloudwu/skynet/issues/1522 for https://github.com/lunarmodules/luasocket/issues/349 for https://github.com/xHasKx/luamqtt/issues/38
gcc——toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2 lua:5.1.5 skynet:1.5.0 mqtt:3.4.2
My code is as follows:
The mqTT_client is ready when the client is connected to the broker and three topics are subscribed. The mqTT_client is then stuck at mq_loop: Iteration ()
What is the cause of the jam? Appreciate receiving