leafo / lapis

A web framework for Lua and OpenResty written in MoonScript
http://leafo.net/lapis/
MIT License
3.13k stars 247 forks source link

SQL table creation, "lua entry thread aborted: runtime error: attempt to yield across C-call boundary" #375

Open ghost opened 8 years ago

ghost commented 8 years ago

Here's the offending code:

local db            = require("lapis.db")
local schema        = require("lapis.db.schema")
local types         = schema.types

schema.create_table( 'users', {
    { 'id',         types.id },
    { 'username',   types.varchar( 20 ) },
    { 'password',   types.varchar( 255 ) },
    { 'salt',       types.varchar( 255 ) },
    { 'email',      types.varchar( 255 ) },
    { 'joindate',   types.date },
    { 'usergroup',  types.varchar( 32 ) }
} )

Which produces this result:

2016/01/06 00:24:50 [notice] 13400#0: *5 [lua] mysql.lua:93: create_table(): SQL: CREATE TABLE `users` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `username` VARCHAR(20) NOT NULL,
  `password` VARCHAR(255) NOT NULL,
  `salt` VARCHAR(255) NOT NULL,
  `email` VARCHAR(255) NOT NULL,
  `joindate` DATE NOT NULL,
  `usergroup` VARCHAR(32) NOT NULL
) CHARSET=UTF8;, client: 10.0.2.2, server: , request: "POST /account/register HTTP/1.1", host: "127.0.0.1:1357", referrer: "http://127.0.0.1:1357/account/register"
2016/01/06 00:24:50 [error] 13400#0: *5 lua entry thread aborted: runtime error: attempt to yield across C-call boundary

I'm using the newest LuaJIT from their Git (2.0.4) along with OpenResty (1.9.7.1) and Lapis (1.4.0) from LuaRocks. I'm totally new to this stuff, so if there's anything else I should provide I'll be happy to do so.

leafo commented 8 years ago

I see the create table command is being issued within openresty. How are you executing that code?

ghost commented 8 years ago

If I simply paste it into app.lua with nothing else, it will throw the same error.

local proj          = { }
proj.lapis          = require( "lapis" )
proj.app            = proj.lapis.Application( )
proj.util           = require( "lapis.util" )
proj.model          = require( "lapis.db.model").Model

local db            = require("lapis.db")
local schema        = require("lapis.db.schema")
local types         = schema.types

schema.create_table( 'users', {
    { 'id',         types.id },
    { 'username',   types.varchar( 20 ) },
    { 'password',   types.varchar( 255 ) },
    { 'salt',       types.varchar( 255 ) },
    { 'email',      types.varchar( 255 ) },
    { 'joindate',   types.date },
    { 'usergroup',  types.varchar( 32 ) }
} )
ghost commented 8 years ago

Since I'm using Vagrant, I can send you the Vagrantfile and my project folder so you can boot up and toy around with my installation. That is, if you wanted to.

I'm going to see if I can start over on a fresh machine again and if the same results occur, I can copy the necessary files for starting up my Vagrant machine.

leafo commented 8 years ago

I didn't get a chance to try to reproduce it yet, let me try on my system before I check out the environment.

ghost commented 8 years ago

In the meantime, is there a workaround I could use? Perhaps specific versions of the software required? I was just starting to work with the model and I'm trying to write a script that creates all of the tables if they don't already exist, i.e. when the application is run for the first time.

leafo commented 8 years ago

Sorry for the delay. I hope you were able to figure something out in the meantime.

The issue is that you can't run queries in the initialization phase of lapis. You can either run it on the command line independently of openresty, or run it in an action that matches a request.