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

setting timeout triggers assertion error #24

Open
eulerreich opened this issue Oct 29, 2015 · 0 comments
Open

setting timeout triggers assertion error #24

eulerreich opened this issue Oct 29, 2015 · 0 comments

Comments

@eulerreich
Copy link

I have the following code for the TCP server (modified from the example) in a file named tcp-server.lua.

async = require 'async'
async.tcp.listen({host='localhost', port=4321}, function(client)
   -- Receive:
   client.ondata(function(chunk)
      -- Data:
      print('received: ' .. chunk)

      -- Reply:
      client.write('1')
   end)

   -- Done:
   client.onend(function()
      print('client gone...')
   end)
end)
async.go()

I have the following for a function that retrieves the message sent by the server.

async = require 'async'
function get_msg()
    local msg = nil
    async.tcp.connect({host='localhost', port=4321}, function(client)
        -- Write something
        client.write('something .. ')

        -- Callbacks
        client.ondata(function(chunk)
            print('received: ' .. chunk)
            msg = chunk
            client.close()
        end)

        -- Done:
        client.onend(function()
            print('connection closed...')
        end)
        async.setTimeout(10, function()
            if not silent then
                print('timed out')
            end
            client.close()
        end)
    end)
    async.go()
    return msg
end

I ran th tcp-server.lua in one terminal and then calling get_msg() in a th shell (in another process). The result is

luajit: src/unix/stream.c:1074: uv_shutdown: Assertion `((stream)->io_watcher.fd) >= 0' failed.                                                 
Aborted (core dumped)  

If I comment out the part starting with async.setTimeout then it will return the value as intended. Also if I comment out client.close() in ondata then it will work as well.

The intention is to return the value as soon as possible, but if the server takes too long then return nil on timeout. I would think this is a fairly common scenario? Is this not the right way to do it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant