wahern / cqueues

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

Threading Hangs (FreeBSD 12, openssl:base and openssl:openssl111, lua 5.3 (pkg, and built from source)) #211

Closed llmII closed 5 years ago

llmII commented 5 years ago

The below code should trigger the issue. Have tried on two FreeBSD 12.0-RELEASE-p2 systems and this is the code abstracted out of something else I was working on that seems to demonstrate the issue best.

local cqueues = require 'cqueues'
local thread = require 'cqueues.thread'

local function print_data(sock, data) print(data) end
local function start() thread.start(print_data, 'data') end

local loop = cqueues.new()
loop:wrap(start)
loop:loop()

Some possible directions to look are - Line 340 in thread.c .

fprintf sprinkling like the below modification around Line 340 basically pointed at it and I'm at a loss as to what would be causing that function to hang.

    fprintf(stderr, "Here we go.");
    if (!(L = luaL_newstate())) {
        fprintf(stderr, "Never seen, we are hung");
        goto syerr;
    }
    fprintf(stderr, "We made it.");
llmII commented 5 years ago

Further looking into this issue it would seem that in FreeBSD 11 lua53 port was built with pthreads linked, whereas it seems this has changed in FreeBSD 12. The change was unexpected and building lua from source, editing src/Makefile and adding '-pthread' to LDFLAGS fixes this issue. Waiting on https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=235158 to see if this is intended, and one should always build their own lua, or if this will be fixed to work as before.

daurnimator commented 5 years ago

@RussellHaley

See https://github.com/wahern/cqueues/blob/36b4b8cf1d8d3e3224cab04357dda3a633c7f0ff/doc/cqueues.tex#L155

RussellHaley commented 5 years ago

Hi @daurnimator,

We had an email conversation about this issue that ended inconclusively (Re: Luaossl on FreeBSD). There was evidence that the bug creating this issue had been resolved which was documented in the Lua53 port review https://reviews.freebsd.org/D13690. I was told it was fixed by the commit here: https://svnweb.freebsd.org/base?view=revision&revision=276630. I had asked you if there was tests I could run to confirm this bug either way, but none were forthcoming. I then assumed the test I had run was adequate. I apologize for the mistake.

Is it possible for someone to provide a test that I can run to validate any fix that comes out of this? My preference is a fix for FreeBSD if possible, but I assume at this point I'll need to add an option to the port.

@llmII I will make further comments in the bugzilla issue you opened. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=235158

Once again, apologies to all.

RussellHaley commented 5 years ago

Sorry, I just saw the test code in the initial message. I'll work with that unless there is something more extensive. Cheers.

RussellHaley commented 5 years ago

I've put forward a patch for the FreeBSD port Makefile that adds pthread as a build option (Lua 53 only). Review here: https://reviews.freebsd.org/D18939

daurnimator commented 5 years ago

@RussellHaley thanks for sorting it out :)

RussellHaley commented 5 years ago

Glad I could help! I'm still waiting for the patch to get pushed up. I'm pleased that we found a regression in FreeBSD.