Hello!
On Thu, Sep 12, 2013 at 8:56 AM, sdureau wrote:
> I'm having issues with the busy socket error.
>
Every time you get the "socket busy" error, it means that you've made
a mistake by accessing the same cosocket object from two Lua "light
threads" (or two concurrent request handlers) at the same time.
> I've 12 worker processes in which I use :
>
This has nothing to do with the number of Nginx worker processes, BTW.
> in the "module_a" Lua module, I have :
>
> local mysql = require "resty.mysql"
> local db, err = mysql:new()
>
Here you make a mistake by creating a resty.mysql object (i.e., a
cosocket object) on the Lua module level, which means that all the
concurrent requests in each nginx worker process *may* access this Lua
module level cosocket at the same time, leading to the "socket budy"
error, see
http://wiki.nginx.org/HttpLuaModule#Data_Sharing_within_an_Nginx_Worker
Actually this is also documented in lua-resty-mysql's README file. To quote:
"The resty.mysql object instance cannot be stored in a Lua variable at
the Lua module level, because it will then be shared by all the
concurrent requests handled by the same nginx worker process (see
http://wiki.nginx.org/HttpLuaModule#Data_Sharing_within_an_Nginx_Worker
) and result in bad race conditions when concurrent requests are
trying to use the same resty.mysql instance. You should always
initiate resty.mysql objects in function local variables or in the
ngx.ctx table. These places all have their own data copies for each
request."
See https://github.com/agentzh/lua-resty-mysql#limitations for more details.
BTW, please join this mailing list before posting otherwise your posts
always require manual moderation. To subscribe, just send an empty
mail to the address openresty-en+subscribe@googlegroups.com. Thank you
for your cooperation!
Regards,
-agentzh