Edge devices stopped accepting TCP connections after firmware update

Immediately after the firmware update to 000.046.00008, my edge devices stopped accepting TCP connections.

In my LUA code I setup the server:

    local serversock = assert(socket.tcp(), "create TCP socket")
    assert(serversock:bind('*', 0))

Then I register a listener

driver:register_channel_handler(serversock, watch_socket, 'server')

But nothing ever shows up and the client says either connection refused or timeout. Interestingly enough, the driver can send out TCP requests successfully. (this is how I handshake)

Any thoughts? I pretty much dead in the water here…

Silly question - you tried rebooting the hub? :slight_smile:

Sadly yes… I “turned if off and then back on again”. :slight_smile:

Anyone out there have the latest firmware and working server code? It’s probably something I inadvertently took a dependency on that I shouldn’t have…

1 Like

tagging @nayelyz

Hi, @mwilkie! It’s great to have you back in the Community.

I asked the engineering team about this and they mentioned that it’s best to use the implementation below instead of register_channel_handler because there are some issues with it that are still under analysis.

  local client = serversock:accept()

Please, let us know your results.

1 Like

Probably doing something silly wrong as I’m not really a LUA guy, but here’s what I get now:

2023-01-24T18:24:01.798031866+00:00 FATAL Admin  Lua: runtime error: [string "cosock.lua"]:296: [string "cosock/socket/tcp.lua"]:42: transform called on error from accept
stack traceback:
        [C]: in function 'assert'
        [string "cosock/socket/tcp.lua"]:42: in function <[string "cosock/socket/tcp.lua"]:41>
        (...tail calls...)
        [string "_myserver.lua"]:184: in function <[string "_myserver.lua"]:183>
stack traceback:
        [C]: in function 'error'
        [string "cosock.lua"]:296: in field 'run'
        [string "st/driver.lua"]:764: in method 'run'
        [string "init.lua"]:192: in main chunk

Found it, serversock:settimeout(0) is no longer valid apparently. In fact, any timeout seems to throw the error.

Regardless, using the new pattern with cosock and removing my timeout seems to have unblocked me.

Here’s what seems to be working now. If someone could check my work as I’m not 100% sure I’ve got all the right bits here, that’s be fantastic.

local function start_server(driver)

    -- Startup Server
    local serversock = socket.tcp()
    serversock:bind('*', 0)

    commonglobals.server_ip, commonglobals.server_port = serversock:getsockname()
    log.info(string.format('**************************  Server started at %s:%s', commonglobals.server_ip, commonglobals.server_port))

    --Spawn thread to accept incoming connections
      while true do
        local client = serversock:accept()
        log.debug("Accepted connection from", client:getpeername())
    end,"server loop")

I was having the same problem and this fixed it. Thanks.

1 Like

I had the same problem and this fixed it. Many Thanks.