Hello!
2013/2/1 307413083:
> 在使用lua-resty-mysql 的时候,应用压力比较大时会出现:
> failed to send query: cannot send query in the current context 异常
>
> 能指点一下这个错误什么原因引起的? 怎么避免?
出现这个错误是因为你上一个 MySQL 查询的结果集没有读取完毕,然后你就尝试发送新的 SQL
查询。一个常见的情况是,上一个查询返回了多个结果集,用户只读取了第一个。细节请参见官方文档中的这一段:
https://github.com/agentzh/lua-resty-mysql#read_result
特别是文档中的这一段:
If more results are following the current result, a second err return
value will be given the string again. One should always check this
(second) return value and if it is again, then she should call this
method again to retrieve more results. This usually happens when the
original query contains multiple statements (separated by semicolon in
the same query string) or calling a MySQL procedure.
在 lua-resty-mysql 库的测试集中也有专门一个测试用例,测试没有检查 err 返回值为 "again"
就直接发起下一个查询而导致返回“failed to send query: cannot send query in the current
context”的错误:
https://github.com/agentzh/lua-resty-mysql/blob/master/t/sanity.t#L505
我查了一下邮件记录,发现你一直是通过直接给我发邮件来寻求技术支持,在此我再一次地建议你加入 openresty
中文邮件列表,并总是在那里发邮件寻求帮助。细节请见 http://openresty.org/#Community
提问自然有提问的地方,请尊重我定下的规矩,谢谢合作。
Best regards,
-agentzh