ZeroBraneStudio icon indicating copy to clipboard operation
ZeroBraneStudio copied to clipboard

Timeout issue in socket library delivered with ZeroBraneStudio

Open jjvbsag opened this issue 7 years ago • 7 comments

See https://github.com/diegonehab/luasocket/issues/234 Do you patch luasocket by yourself ? Or do you need to wait for a fix at https://github.com/diegonehab/luasocket

jjvbsag avatar Oct 27 '17 12:10 jjvbsag

My preference is to wait for it to be patched upstream. You can definitely compile and install it locally.

pkulchenko avatar Oct 27 '17 15:10 pkulchenko

@pkulchenko : OK, I did look a bit more into the details. ZBS uses tag "v3.0-rc1". In the "master" of luasocket the issue is fixed since 2013. Can you switch to master or do you get other issues with that?

jjvbsag avatar Nov 28 '17 11:11 jjvbsag

My preference would be to use release versions (or at least something labeled close to that) and I don't see any newer releases in the repository. You can always compile your own version to use, right?

pkulchenko avatar Nov 28 '17 18:11 pkulchenko

@jjvbsag, I got a couple of simple scripts to test this and don't see any issue with the timeouts (at least on Windows where I'm testing). Maybe the issue has already been fixed in the version that the IDE is using?

Here are the scripts.

Server:

local socket = require("socket")
-- create a TCP socket and bind it to the local host, at any port
local server = assert(socket.bind("*", 64900))
-- find out which port the OS chose for us
local ip, port = server:getsockname()
-- print a message informing what's up
print("Connect to localhost on port " .. port)
-- loop forever waiting for clients
while 1 do
  -- wait for a connection from any client
  local client, err = server:accept()
  print(client, err)
  while 1 do
    local line, err = client:receive()
    print(line or err)
    if err then break end
    client:send(line .. "\n")
  end
  -- done with client, close the object
  client:close()
end

Client:

local socket = require "socket"
local sock=assert(socket.connect("localhost",64900))
sock:settimeout(5.0) -- set timeout
while true do
	assert(sock:send("Hello!\n"))
	print(assert(sock:receive()), os.clock())
	io.flush()
	socket.sleep(0.1)
end

When I start the server and then run the client, I see the output continuing after 5 seconds (which is what I'd expect). I waited for 60 seconds, but it would probably continue indefinitely, so I don't see the issue you are describing.

pkulchenko avatar Nov 28 '17 19:11 pkulchenko

@pkulchenko Dear Paul, I had trouble with this since years (the same fault was in ubuntu14.04 repository). I know it, when I see it. Now, thats what I did (All on Ubuntu 16.04):

  • Created an empty directory .../SocketTimeout
  • Saved your to snippets from above as server.lua and client.lua
  • Started server.lua from commandline
  • Started client.lua from fresh ZeroBrane Studio (1.70; MobDebug 0.702)

That's what I got:

Program starting as '"/opt/zbstudio/bin/linux/x64/lua" -e "io.stdout:setvbuf('no')" "/home/proj/Lua/SocketTimeout/client.lua"'.
Program 'lua' started in '/home/proj/Lua/SocketTimeout' (pid: 5108).
Hello!	0.002854
Hello!	0.002984
Hello!	0.003102
Hello!	0.003208
Hello!	0.003315
Hello!	0.003422
Hello!	0.003528
Hello!	0.003636
Hello!	0.003767
Hello!	0.003879
Hello!	0.00399
Hello!	0.004101
Hello!	0.00423
Hello!	0.004342
Hello!	0.004455
Hello!	0.00456
Hello!	0.004671
Hello!	0.004786
Hello!	0.004901
Hello!	0.005018
Hello!	0.005123
Hello!	0.005218
Hello!	0.005334
Hello!	0.005447
Hello!	0.005564
Hello!	0.005686
Hello!	0.005802
Hello!	0.00592
Hello!	0.006034
Hello!	0.006147
Hello!	0.006314
Hello!	0.006423
Hello!	0.006542
Hello!	0.006664
Hello!	0.006778
Hello!	0.006888
Hello!	0.007002
Hello!	0.007105
Hello!	0.007216
Hello!	0.007368
Hello!	0.007488
Hello!	0.00761
Hello!	0.007726
Hello!	0.007838
Hello!	0.00795
Hello!	0.008063
Hello!	0.008173
Hello!	0.008302
Hello!	0.008422
Hello!	0.008539
/opt/zbstudio/bin/linux/x64/lua: /home/proj/Lua/SocketTimeout/client.lua:6: timeout
stack traceback:
	[C]: in function 'assert'
	/home/proj/Lua/SocketTimeout/client.lua:6: in main chunk
	[C]: at 0x00404f08
Program completed in 5.03 seconds (pid: 5108).

If you use the same source for Linux and Windows, It's not clear to me, why this does not happen on windows. I checked on windows too without any fault.

I tried the same with the lua installed with ubuntu ¹), client runs forever without timeout.

So it's clearly the lua socket delivered with ZBS in linux.


¹) I did with the following as lualinux51.luain interpreters

dofile 'interpreters/luabase.lua'
return MakeLuaInterpreter("ubuntu5.1", ' Ubuntu 5.1')

and path.luaubuntu51 = '/usr/bin/lua5.1' in user.lua

jjvbsag avatar Nov 29 '17 07:11 jjvbsag

If you use the same source for Linux and Windows, It's not clear to me, why this does not happen on windows. I checked on windows too without any fault.

Yes, it's most definitely the same source, as I used the same script and version to rebuild all supported platforms. I agree it's strange, as buffer.c doesn't look to be system dependent. I'll check on the Ubuntu VM I have.

pkulchenko avatar Nov 30 '17 03:11 pkulchenko

@pkulchenko Any chance to update luasocket for upcoming 1.90 ?

jjvbsag avatar Nov 07 '19 07:11 jjvbsag