Hello!
On Mon, Oct 6, 2014 at 7:26 AM, Michal Cichra wrote:
> 2014/10/06 16:22:46 [error] 47946#0: lua entry thread aborted: runtime
> error: attempt to yield across C-call boundary
> stack traceback:
> coroutine 0:
> [C]: in function 'XML_Parse'
This XML_Parse is the culprit. It is a C function which calls your
user callback requiring yielding (for nonblocking IO and etc). You
need to ensure the caller of your user callback to be a Lua function
(as well as the caller's caller, and etc).
>
> Because in our project we run user's code, they can do IO. They can write to
> database and do other things. Logging is implemented by IO.
>
This is fine as long as the user code's caller is implemented as a Lua
function (and none of the caller's ancestor is a C function).
> This feels especially weird because Nginx tries to be non blocking, so all
> the XML parsing, JSON stream parsing will have to be implemented as
> callbacks (expat, yajl).
>
In the model used by ngx_lua, we actually avoid the callback style
wherever possible. We use the iterative style which is callback free.
For example, the cosocket API is synchronous but 100% nonblocking.
Also, the lua-resty-upload library implements a multipart request body
streaming parser without introducing a callback-based API:
https://github.com/openresty/lua-resty-upload#readme
Regards,
-agentzh